Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 344942

Summary: Classloader issue while un-/marshalling with Moxy
Product: z_Archived Reporter: Stefan W. <comikus15>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: matt.macivor
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch to solve the problem
matt.macivor: iplog+
Fix for the same issue with XmlSeeAlso none

Description Stefan W. CLA 2011-05-06 06:04:24 EDT
Build Identifier: 2.2.0.v20110202-r8913

If i have following setup:
- Bundle A containing XJC generated classes and a facade for the marshalling code
- Bundle B has the un-/marshaller code
- An UI thread calls the facade from Bundle A with an classloader which can load classes from every OSGi bundle

The JAXBContext is created using the above mentioned classloader:
JAXBContextFactory.createContext(contextPath, classLoader);

While creating the context, the ObjectFactory.java from the generated classes in Bundle A is loaded and check if it is a JAXB ObjectFactory. The check fails because the check, if the class is annotated as object factory, is done with the wrong classloader (see line 153 and 379 ind JAXBContextFactory.java [trunk version]). Furthermore the check is done without a classloader.

So the situation is somehting like this: the supplied object factory class in method isJAXB2ObjectFactory is loaded by my own classloader (and hence the annotations in it) while the annotation which is used to the check it is loaded with the UI threads classloader. Thus the method returns false and the ObjectFactory check is worthless.

Reproducible: Always
Comment 1 Stefan W. CLA 2011-05-06 06:07:19 EDT
Created attachment 194918 [details]
Patch to solve the problem

This patch passes the classloader to the isJAXB2ObjectFactory and loads the annotation with the specific classloader.

The patch is for the trunk version of moxy. 
If a patch for the specific version 2.2.0.v20110202-r8913 is need i can supply it too.
Comment 2 Matt MacIvor CLA 2011-05-09 14:57:01 EDT
Created attachment 195127 [details]
Fix for the same issue with XmlSeeAlso
Comment 3 Matt MacIvor CLA 2011-05-09 14:58:19 EDT
Proposed fix looks good.

The same issue exists for the XmlSeeAlso annotation. That annotation class is also loaded using the same API without passing in the correct ClassLoader.
Comment 4 Matt MacIvor CLA 2011-05-09 15:24:34 EDT
Attached patches checked into trunk stream in SVN
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:14:16 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:29:33 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink