Hi,

I've been adding osgi integration test on core and I found a
classloading problem revolving around cglib enhancer.
The main problem is enhancer uses fragment class class loader to
create an enhanced class. If the fragment class
bundle does not import net.sf.cglib.proxy package, the enhancer will
throw a ClassDefNotFoundError exception.

I googled this topic and found interesting discussion:
http://groups.google.com/group/spring-osgi/browse_frm/thread/d921aaec07c3a5be/41b387ffde4c715b?lnk=gst&q=cglib&pli=1

I think Stuart's solution to subclass Enhancer and override
Enhancer#getClassLoader() would be the way to go.

wdyt?

Regards,
Edward Yakop

Potential OSGi future direction:
http://www.osgi.org/blog/2007/07/to-declare-or-not-to-declare.html

Sample exception: Note: I modified some qi4j core code (not
committed), hence it won't match line number of respective classes
Caused by: java.lang.RuntimeException: Fail to instantiate [class
org.qi4j.service.ServiceComposite$ServiceCompositeMixin]
        at 
org.qi4j.runtime.composite.ConstructorsModel.instantiationClass(ConstructorsModel.java:224)
        at 
org.qi4j.runtime.composite.ConstructorsModel.<init>(ConstructorsModel.java:51)
        at org.qi4j.runtime.composite.MixinModel.<init>(MixinModel.java:54)
        at 
org.qi4j.runtime.composite.AbstractMixinsModel.implementMethodWithClass(AbstractMixinsModel.java:164)
        at 
org.qi4j.runtime.composite.AbstractMixinsModel.implementMethod(AbstractMixinsModel.java:89)
        at 
org.qi4j.runtime.composite.MixinsModel.implementMethod(MixinsModel.java:40)
        at 
org.qi4j.runtime.composite.CompositeMethodsModel.implementMixinType(CompositeMethodsModel.java:89)
        at 
org.qi4j.runtime.composite.CompositeMethodsModel.<init>(CompositeMethodsModel.java:51)
        at 
org.qi4j.runtime.composite.CompositeModel.newModel(CompositeModel.java:67)
        at 
org.qi4j.runtime.bootstrap.ModuleAssemblyImpl.assembleModule(ModuleAssemblyImpl.java:241)
        at 
org.qi4j.runtime.bootstrap.ApplicationFactoryImpl.newApplication(ApplicationFactoryImpl.java:123)
        at 
org.qi4j.runtime.bootstrap.ApplicationFactoryImpl.newApplication(ApplicationFactoryImpl.java:84)
        at 
org.qi4j.runtime.bootstrap.ApplicationFactoryImpl.newApplication(ApplicationFactoryImpl.java:53)
        at org.qi4j.bootstrap.Energy4Java.newApplication(Energy4Java.java:60)
        at org.qi4j.core.test.osgi.internal.Activator.start(Activator.java:48)
        at 
org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:1009)
        at java.security.AccessController.doPrivileged(Native Method)
        at 
org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1003)
        ... 10 more
Caused by: net.sf.cglib.core.CodeGenerationException:
java.lang.reflect.InvocationTargetException-->null
        at 
net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
        at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
        at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
        at 
org.qi4j.runtime.composite.ConstructorsModel.instantiationClass(ConstructorsModel.java:217)
        ... 27 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
        at 
net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
        ... 30 more
Caused by: java.lang.NoClassDefFoundError: net/sf/cglib/proxy/Factory
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        ... 36 more

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to