Home » Eclipse Projects » Equinox » bundle class loaders caching issues?
bundle class loaders caching issues? [message #79909] |
Wed, 27 December 2006 09:41  |
Eclipse User |
|
|
|
Originally posted by: david.eauee.gmail.com
Hi,
I have a weird situation here were multiple calls to the "JAXBContext.newInstance(...)" causes an avalanche of "java.lang.LinkageError: duplicate class definition:..." error being spit out. I have copied a sample stack trace at the end of this mail
This call is made indirectly by one of the lib my plug-in is using.
The lib itself is hosted by a separate binary plug-in that also contains all the other dependant jars that i require.
Just to make sure I checked that the offending classes were not present more than once in the build path.
The weird thing is that the 1st call to the method returns happily but each one after that will fail. Dont the bundle class loaders have a caching mechanism to prevent them from trying to load the same class multiple times?
Has anybody come across this before?
Thanks,
David.
stack trace:
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Inje ctor.java:125)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Inje ctor.java:48)
at com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.pre pare(AccessorInjector.java:51)
at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFac tory.get(OptimizedAccessorFactory.java:128)
at com.sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection .optimize(Accessor.java:198)
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$Compo siteTransducedAccessorImpl. <init>(TransducedAccessor.java:193)
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor.get(T ransducedAccessor.java:135)
at com.sun.xml.bind.v2.runtime.property.AttributeProperty.<init >(AttributeProperty.java:53)
at com.sun.xml.bind.v2.runtime.property.PropertyFactory.create( PropertyFactory.java:68)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:135)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXB ContextImpl.java:404)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:122)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXB ContextImpl.java:404)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:122)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXB ContextImpl.java:404)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:246)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFact ory.java:76)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFact ory.java:55)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFact ory.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java: 132)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:286)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
...
Caused by: java.lang.LinkageError: duplicate class definition: ...
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
... 72 more
|
|
| | | | | | |
Re: bundle class loaders caching issues? [message #80674 is a reply to message #80522] |
Thu, 11 January 2007 04:34   |
Eclipse User |
|
|
|
sorry for not replying for the past few days (was sick)
You are correct Alex, The "injector" class from the JAXB impl really
goes out of it way to "force define" classes: it retrieves the Method
handle from Classloader.class, reset its accessibility settings and call
invoke on it directly (see the snippets from the injector class at the end)
Now, I have no idea why in the 1st place JAXB seems to believe that it
needs to go to such extremes to load classes (generated on the fly) that
the class loader knows about already.
That said, as a colleague of mine mentioned on java.net (the thread you
referenced earlier) we came across a work around: setting the env var
"com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize" will cause JAXB to
avoid that code completely. For now we are content enough with that
resolution.
i will open a bug...
Regarding replicating the issue, I think the simplest would be to import
a recent apache cxf distrib (which includes and uses JAXB) in a plugin,
attach the srcs to the jar and call some of their their wsdl related
APIs. Would that be ok?
thanks,
d.
#############################
.....
private static final Method defineClass;
private static final Method resolveClass; ....
defineClass =
ClassLoader.class.getDeclaredMethod("defineClass",String.class,byte[].cl
ass,Integer.TYPE,Integer.TYPE);
resolveClass =
ClassLoader.class.getDeclaredMethod("resolveClass",Class.class);
.....
// TODO: check security implication
// do these setAccessible allow anyone to call these methods freely?s
defineClass.setAccessible(true);
resolveClass.setAccessible(true);
....
(Class)defineClass.invoke(parent,className.replace('/','.'), image,0,imag
e.length);
resolveClass.invoke(parent,c);
.....
#############################
Alex Blewitt wrote:
> It did seem to be by the original report/stack trace:
>
> .. multiple calls to the "JAXBContext.newInstance(...)" causes an avalanche of "java.lang.LinkageError: duplicate class definition:. ...
>
> stack trace:
>
> java.lang.reflect.InvocationTargetException
> at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Inje ctor.java:125)
> at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.inject(Inje ctor.java:48)
> :
> Caused by: java.lang.LinkageError: duplicate class definition: ...
> at java.lang.ClassLoader.defineClass1(Native Method)
>
> It looks like the JAXB is doing a dynamic method call to build up the bytecode, which in turn is then invoking the defineClass when it's already defined. I suspect that if you put together a quick ClassLoader and overrode the defineClass() method to print out diagnostics, you'd see the same thing. Alternatively, putting a breakpoint in the defineClass and using a JAXB sample would do the trick :-)
>
> David, would you be able to open a bug at https://bugs.eclipse.org and attach a snippet that exhibits this problem? At least that way we could verify whether it's a JAXB issue or not.
>
> Alex.
|
|
|
Re: bundle class loaders caching issues? [message #80695 is a reply to message #80674] |
Thu, 11 January 2007 09:24  |
Eclipse User |
|
|
|
Originally posted by: alex_blewitt.yahoo.com
> You are correct Alex, The "injector" class from the JAXB impl
> really goes out of it way to "force define" classes: it retrieves
> the Method handle from Classloader.class, reset its accessibility
> settings and call invoke on it directly.
Cool, glad we found that error.
> Now, I have no idea why in the 1st place JAXB seems to believe
> that it needs to go to such extremes to load classes ...
A cynic might point out that JAXB is written by Sun, and that they don't like Eclipse or any of that nasty little OSGi stuff that it runs on when there's a perfectly good JSR277 around the corner :-)
> Regarding replicating the issue, I think the simplest would be
> to import a recent apache cxf distrib (which includes and uses
> JAXB) in a plugin, attach the srcs to the jar and call some of
> their their wsdl related APIs. Would that be ok?
The easier it is for the Eclipse guys to reproduce it, the easier that they can see what to do about it. A few lines that invoke (say) the WS code, and a 'download the Jar from http://...' would probably do.
That being said, I suspect it might be that the JAXB code is behaving badly, and that it turns out that it's not an issue that Equinox can work around anyway. So I wouldn't spend *too* long on it :-)
Alex.
PS I'm not an Eclipse committer; if you raise a bug, they may have different opions about reproducibility :-)
|
|
|
Goto Forum:
Current Time: Fri May 02 18:18:24 EDT 2025
Powered by FUDForum. Page generated in 0.04183 seconds
|