Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325179 - javax.xml.bind bundle fails to instantiate JAXB implementation
Summary: javax.xml.bind bundle fails to instantiate JAXB implementation
Status: NEW
Alias: None
Product: Orbit
Classification: Tools
Component: bundles (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Blaise Doughan CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 325176 345149
  Show dependency tree
 
Reported: 2010-09-13 19:07 EDT by Steffen Pingel CLA
Modified: 2012-01-20 14:05 EST (History)
4 users (show)

See Also:


Attachments
fix (1.06 KB, patch)
2010-09-13 19:08 EDT, Steffen Pingel CLA
no flags Details | Diff
simple test (3.55 KB, application/octet-stream)
2010-09-14 17:47 EDT, Steffen Pingel CLA
no flags Details
fix for all versions expect javax.xml.bind 2.0.0 (5.37 KB, text/plain)
2010-09-14 18:45 EDT, Steffen Pingel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steffen Pingel CLA 2010-09-13 19:07:56 EDT
If the javax.xml.bind bundle is used with com.sun.xml.bind on Java 5 which does not ship with a JAXB binding (only Java 6 does) a ClassNotFoundException exception occurs when a JAXBContext.newInstance() is invoked (see bug 325176).

I believe javax.xml.bind needs to specify a dependency or buddy policy in order to be able to load classes from com.sun.xml.bind.
Comment 1 Steffen Pingel CLA 2010-09-13 19:08:28 EDT
Created attachment 178779 [details]
fix
Comment 2 David Williams CLA 2010-09-14 01:17:22 EDT
(In reply to comment #0)

> I believe javax.xml.bind needs to specify a dependency or buddy policy in order
> to be able to load classes from com.sun.xml.bind.

Well, javax.xml.bind should be able to load classes from com.sun.xml.bind just fine ... are you saying the reverse? That javax.xml.bind "finds" the factory in com.sun.xml.bind but then the sun package class tries to load something from java.xml.bind? I think that "reversed" situation is what requires buddy class loading.
Comment 3 David Williams CLA 2010-09-14 01:20:18 EDT
Oh, you are saying there's no dependency specified between the two?
Comment 4 Steffen Pingel CLA 2010-09-14 02:43:24 EDT
The com.sun.xml.bind bundle does depend on javax.xml.bind but that does not help with this problem. 

The standard way of creating a JAXB context is through invoking the factory defined in the javax.xml.bind package. This works fine on Java 6 where the implementation and API live in the system.bundle class loader since the javax.xml.bind package comes from the JDK and not the Orbit bundle.

On Java 5 the javax.xml.bind Orbit bundle tries to create an instance of a class that comes from com.sun.xml.bind which fails since it can't actually see it (no idea how it knows what class to create but it does know).

This is very similar to how factories such as TransferFormerFactory in the Java XML API work. Did this problem ever arise with the javax.xml bundle?
Comment 5 Gunnar Wagenknecht CLA 2010-09-14 03:02:18 EDT
We have a similar requirement with SLF4J bundles. It tries to load classes from other bundles contributed at runtime.  Buddy-Classloading is one option but not the best one. A better one could be fragments in combination with the extensible API header.
Comment 6 David Williams CLA 2010-09-14 03:02:54 EDT
I've not see it with the javax.xml bundle, but never saw a case there the factory was in a different bundle (either in vm, or a bundle dependency). 

Can't say I understand it completely, but I've not issue applying the patch if you know for sure that'll help, and you really (really) need it to run on Java 1.5 (I say it that way, since sounded like in original post, the user was accidentally use java 1.5, that he didn't need to). 

There's a lot of "contact names" listed for this one ... so, I'll add them to CC and see if any of them have any advice.
Comment 7 Oisin Hurley CLA 2010-09-14 05:03:39 EDT
There's a number of versions of JAXB and the Sun implementation registered with Orbit, and I am pretty sure that this worked without issue for the version of JAXB that I had submitted (2.1.9), because we shipped it as product with Galileo. I'm certainly not against applying the patch if it fixes the issue.
Comment 8 Gunnar Wagenknecht CLA 2010-09-14 05:09:11 EDT
Was this patch tested with multiple versions of com.sun.xml.bind in place? I think there is an issue which might cause incompatible versions registered with each other in future releases.
Comment 9 Steffen Pingel CLA 2010-09-14 12:49:32 EDT
I don't see any differences with the 2.1.9 version of the JAXB bundle but I'll try it. Does Orbit have JUnit tests?
Comment 10 David Williams CLA 2010-09-14 13:19:27 EDT
(In reply to comment #9)
> ... Does Orbit have JUnit tests?

No. There are a few "releng tests" ran, just to confirm results are in right form, etc., but nothing really "runs".
Comment 11 Blaise Doughan CLA 2010-09-14 14:47:29 EDT
The solution should not require that the javax.xml.bind bundle load com.sun.xml.bind bundle.  This is because a JAXB impl other than the reference implementation may be used, such as EclipseLink JAXB.
Comment 12 Gunnar Wagenknecht CLA 2010-09-14 14:52:00 EDT
(In reply to comment #9)
> I don't see any differences with the 2.1.9 version of the JAXB bundle but I'll
> try it. Does Orbit have JUnit tests?

Sorry, I was talking about running multiple versions concurrently (OSGi is about running multiple versions at the same time). It should only tie versions together that belong together.

(In reply to comment #11)
> The solution should not require that the javax.xml.bind bundle load
> com.sun.xml.bind bundle.  This is because a JAXB impl other than the reference
> implementation may be used, such as EclipseLink JAXB.

How do you currently enable this? Lets say both impl bundles are installed, who decides which one to instantiate and how?
Comment 13 Steffen Pingel CLA 2010-09-14 17:47:41 EDT
Created attachment 178886 [details]
simple test
Comment 14 Steffen Pingel CLA 2010-09-14 18:45:04 EDT
> Sorry, I was talking about running multiple versions concurrently (OSGi is about
> running multiple versions at the same time). It should only tie versions
> together that belong together.

The package imports in the com.sun.xml.bind packages would need to specify version constraints accordingly to ensure that right versions get wired together. Currently com.sun.xml.bind does not specify any constraints on the javax.xml.bind imports which would need to get fixed.

> (In reply to comment #11)
> > The solution should not require that the javax.xml.bind bundle load
> > com.sun.xml.bind bundle.  This is because a JAXB impl other than the reference
> > implementation may be used, such as EclipseLink JAXB.
> 
> How do you currently enable this? Lets say both impl bundles are installed, who
> decides which one to instantiate and how?

Isn't this non deterministic to some degree? The JAXB API has some sort of lookup order to find the implementation but in the end it might depend on what bundle it comes across first.

I ran a few more tests with various version of JAXB and Java. If I specify a version constraint on javax.xml.bind in the package import of the test bundle and run on Java 6 I get this error:

java.lang.NullPointerException
	at javax.xml.bind.ContextFinder.handleClassCastException(ContextFinder.java:95)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:204)
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:375)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:618)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:565)
	at org.eclipse.orbit.tests.javax.xml.bind.JAXBTest.testNewInstance(JAXBTest.java:14)
	
I believe this is caused by the javax.xml.bind package coming from two different sources, the JRE and the javax.xml.bind bundle. This should be solved by adding a requirement on system.bundle to javax.xml.bind.

I'll attach a new patch which worked in the various combinations of package imports and Java versions but we'll probably end up wiring Mylyn to the concrete JAXB implementation in com.sun.xml.bind and not rely on the factory provided by javax.xml.bind to avoid any funny problems.
Comment 15 Steffen Pingel CLA 2010-09-14 18:45:49 EDT
Created attachment 178888 [details]
fix for all versions expect javax.xml.bind 2.0.0
Comment 16 David Williams CLA 2011-03-02 12:57:10 EST
This is getting pretty old. Still an issue? What action is desired here? 

(I've only skimmed previous comments ... just enough to make my head spin :)
Comment 17 Steffen Pingel CLA 2011-03-03 18:55:28 EST
I believe that using JAXBContext.newInstance() with the current javax.xml bundles does not work. Allowing JAXB implementations to register as a buddy as proposed in the patch would be one way to fix it. 

Another work-around, which we used for Mylyn, is to instantiate the JAXB implementation directly instead of going through the factory. So... it's not fixed but there is a work-around. 

I can't tell if it's worth taking action or if there are better solutions than the proposed patch. I would leave this report open though for documentation purposes and to gather more input in case other consumers run into the same problem.
Comment 18 David Williams CLA 2011-03-03 22:19:37 EST
Ok, we'll just leave this open as an enhancement request, and see if anyone has any other advice or needs. Maybe if nothing comes up by Indigo release, close as 'won't fix'. 

Thank you.
Comment 19 Steffen Pingel CLA 2011-05-31 21:41:12 EDT
There is another related problem that causes the Mylyn Hudson integration to fail when it is used on Java 1.6 with the JEE package: bug 345149: java.lang.VerifyError when connecting to Jenkins server with JEE package.

As far as I can tell,  this is happening because javax.xml.bind 2.1.9 is already part of the JEE package and getting javax.xml.bind 2.2.0 installed in addition causes the VerifyError. I haven't verified if the patch fixes it but wanted to record it here in case someone else encounteres the same problem.
Comment 20 David Williams CLA 2012-01-20 14:05:15 EST
Assigning to Blaise as most recent "contact" for this bundle. 

Blaise, can you assess and/or commit patches if appropriate? 

I'm assuming, at this late date, this would be for Juno only ... not part of Indigo SR2.