Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 344942 - Classloader issue while un-/marshalling with Moxy
Summary: Classloader issue while un-/marshalling with Moxy
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-06 06:04 EDT by Stefan W. CLA
Modified: 2022-06-09 10:29 EDT (History)
1 user (show)

See Also:


Attachments
Patch to solve the problem (1.21 KB, patch)
2011-05-06 06:07 EDT, Stefan W. CLA
matt.macivor: iplog+
Details | Diff
Fix for the same issue with XmlSeeAlso (1.01 KB, patch)
2011-05-09 14:57 EDT, Matt MacIvor CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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