PDA

View Full Version : Failed to get class loader for bundle



esammer
Mar 11th, 2009, 11:42 AM
I've built a bundle that, when deployed, results in a NPE within the internals of dm Server. Specifically, the error is in org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader, but that's probably neither here nor there.

This is a relatively simple bundle containing no imports or exports: it's in a transitional stage where all dependencies are contained internally. I know it's not ideal, but this is the current case.

My manifest looks like this:



Bundle-SymbolicName: com.mycompany.myapp
Bundle-ManifestVersion: 2
Bundle-Name: myapp
Bundle-Vendor: com.mycompany
Bundle-ClassPath: classes/,
lib/,
.
Bundle-Version: 1.0.1



..and my bundle layout:



META-INF/
MANIFEST.MF
<other files like persistence.xml for JPA>
classes/
<class files>
lib/
<internal dependencies>
<misc resources>


According to the trace logs, the file is detected as a legacy jar and the manifest is (seemingly properly) rewritten to import one of the dm Server kernel core packages which seems fine. During the bundle start up I get this fun and excitement:



14746 com.springsource.server.osgi.framework.OsgiFramewo rkException: Failed to get class loader for bundle 'file:////home/me/path/to/springsource-dm-server-1.0.2.RELEASE/work/com.springsource.server.deployer/Module/myapp-1.0.0.jar-0/myapp-1.0. 0.jar [67]' - possible resolution problem:
14747 null
14748 at com.springsource.server.osgi.framework.equinox.Equ inoxUtils.getBundleClassLoader(EquinoxUtils.java:9 1)
14749 at com.springsource.server.osgi.framework.equinox.Equ inoxOsgiFramework.getBundleClassLoader(EquinoxOsgi Framework.java:243)
14750 at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
14751 at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
14752 at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
14753 at java.lang.reflect.Method.invoke(Method.java:597)
14754 at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:307)
14755 at org.springframework.osgi.service.importer.support. internal.aop.ServiceInvoker.doInvoke(ServiceInvoke r.java:58)
14755 at org.springframework.osgi.service.importer.support. internal.aop.ServiceInvoker.doInvoke(ServiceInvoke r.java:58)
14756 at org.springframework.osgi.service.importer.support. internal.aop.ServiceInvoker.invoke(ServiceInvoker. java:62)
14757 at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
14758 at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.doProceed(DelegatingIntroductionIn terceptor.java:131)
14759 at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.invoke(DelegatingIntroductionInter ceptor.java:119)
14760 at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
14761 at org.springframework.osgi.service.importer.support. LocalBundleContextAdvice.invoke(LocalBundleContext Advice.java:59)
14762 at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
14763 at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.doProceed(DelegatingIntroductionIn terceptor.java:131)
14764 at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.invoke(DelegatingIntroductionInter ceptor.java:119)
14765 at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
14766 at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
14767 at $Proxy77.getBundleClassLoader(Unknown Source)
14768 at com.springsource.server.deployer.core.module.Stand ardModule.pushThreadContextClassLoader(StandardMod ule.java:793)
14769 at com.springsource.server.deployer.core.module.Stand ardModule.pushThreadContext(StandardModule.java:76 5)
14770 at com.springsource.server.deployer.core.module.Stand ardModule.deploy(StandardModule.java:301)
14771 at com.springsource.server.deployer.app.legacy.Single BundleApplication.deploy(SingleBundleApplication.j ava:123)
14772 at com.springsource.server.deployer.core.internal.Sta ndardApplicationDeployer.deploy(StandardApplicatio nDeployer.java:329)
14773 at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
14774 at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
14775 at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
14776 at java.lang.reflect.Method.invoke(Method.java:597)
14777 at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:307)
14778 at org.springframework.osgi.service.importer.support. internal.aop.ServiceInvoker.doInvoke(ServiceInvoke r.java:58)
14779 at org.springframework.osgi.service.importer.support. internal.aop.ServiceInvoker.invoke(ServiceInvoker. java:62)
14780 at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
14781 at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.doProceed(DelegatingIntroductionIn terceptor.java:131)
14782 at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.invoke(DelegatingIntroductionInter ceptor.java:119)
14783 at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
14784 at org.springframework.osgi.service.importer.support. LocalBundleContextAdvice.invoke(LocalBundleContext Advice.java:59)
14785 at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
14786 at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.doProceed(DelegatingIntroductionIn terceptor.java:131)
14787 at org.springframework.aop.support.DelegatingIntroduc tionInterceptor.invoke(DelegatingIntroductionInter ceptor.java:119)
14788 at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
14789 at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
14790 at $Proxy14.deploy(Unknown Source)
14791 at com.springsource.server.deployer.hot.HotDeployment FileSystemListener.deploy(HotDeploymentFileSystemL istener.java:190)
14792 at com.springsource.server.deployer.hot.HotDeployment FileSystemListener.onChange(HotDeploymentFileSyste mListener.java:91)
14793 at com.springsource.server.io.core.fs.WatchTask.notif yListeners(WatchTask.java:194)
14794 at com.springsource.server.io.core.fs.WatchTask.notif yListeners(WatchTask.java:188)
14795 at com.springsource.server.io.core.fs.WatchTask.proce ssMonitoredRecord(WatchTask.java:182)
14796 at com.springsource.server.io.core.fs.WatchTask.run(W atchTask.java:107)
14797 at java.lang.Thread.run(Thread.java:619)
14798 Caused by: java.lang.reflect.InvocationTargetException
14799 at sun.reflect.GeneratedMethodAccessor3.invoke(Unknow n Source)
14800 at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
14801 at java.lang.reflect.Method.invoke(Method.java:597)
14802 at com.springsource.server.osgi.framework.equinox.Equ inoxUtils.getBundleClassLoader(EquinoxUtils.java:8 8)
14803 ... 49 more
14804 Caused by: java.lang.NullPointerException
14805 at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.createProtectionDomain(DefaultClassLoader.j ava:232)
14806 at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.createClassPathEntry(DefaultClassLoader.jav a:161)
14807 at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.createClassPathEntry(ClasspathManager.java:259)
14808 at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.getClasspath(ClasspathManager.java:226)
14809 at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.addClassPathEntry(ClasspathManager.java:189)
14810 at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.findClassPathEntry(ClasspathManager.java:167)
14811 at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.buildClasspath(ClasspathManager.java:145)
14812 at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.initialize(ClasspathManager.java:79)
14813 at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.initialize(DefaultClassLoader.java:181)
14814 at org.eclipse.osgi.framework.internal.core.BundleLoa der.createBCL(BundleLoader.java:845)
14815 at org.eclipse.osgi.framework.internal.core.BundleLoa der.createBCLPrevileged(BundleLoader.java:820)
14816 at org.eclipse.osgi.framework.internal.core.BundleLoa der.createClassLoader(BundleLoader.java:352)
14817 ... 53 more


Just prior to this, there's about 2000+ lines of ThreadLocal.get()s going on which I've never seen before. The application itself has no knowledge of OSGI (no activators, exposed services, reliance on OSGI specific APIs, nothing dm or Spring specific, etc.); I just wanted to get it deployed cleanly before I continue to modify the build further.

The application itself is a Spring app with GridGain and has some AOP stuff going on, but it's not even getting to the app itself. I think this is purely a build / packaging / possible dm bug issue I'm running into.

I'm running the standard Sun JDK 1.6.0_10 on an Ubuntu workstation. I've tried a number of different deployment scenarios with similar results. This is a freshly downloaded and unpacked dm Server 1.0.2. I'm sure it's something I'm doing or a bug being tickled by something I'm doing. Any help is appreciated.

Andy Wilkinson
Mar 11th, 2009, 01:21 PM
It looks like there's a problem in Equinox. The NPE is occurring when it's trying to create a ProtectionDomain for your bundle which is triggered by the creation of the bundle's classloader. Looking at the line in question (DefaultClassLoader.java, line 232) it's not clear why the NPE is occurring. Can you please open a JIRA (https://issuetracker.springsource.com/browse/PLATFORM) and attach a copy of the bundle (or a cut-down version of it) that reproduces the problem and we'll take a look.

esammer
Mar 11th, 2009, 02:37 PM
It looks like there's a problem in Equinox. The NPE is occurring when it's trying to create a ProtectionDomain for your bundle which is triggered by the creation of the bundle's classloader. Looking at the line in question (DefaultClassLoader.java, line 232) it's not clear why the NPE is occurring. Can you please open a JIRA (https://issuetracker.springsource.com/browse/PLATFORM) and attach a copy of the bundle (or a cut-down version of it) that reproduces the problem and we'll take a look.

I've opened JIRA issue PLATFORM-243
https://issuetracker.springsource.com/browse/PLATFORM-243

This includes a (very) stripped down version of the bundle producing the error.

Thanks for the help!

oleg.zhurakousky
Mar 11th, 2009, 08:39 PM
I was able to replicate the problem and then fix it with the file attached.
The issue you are having seem to trace to the fact that legacy WAR should have its META-INF under WEB-INF directory.
By simply moving META-INF directory with MANIFEST to WEB-INF fixes the problem.
So I would suggest to try to do that and then start adding other dependencies.

Andy Wilkinson
Apr 24th, 2009, 10:01 AM
I was able to replicate the problem and then fix it with the file attached.
The issue you are having seem to trace to the fact that legacy WAR should have its META-INF under WEB-INF directory.
By simply moving META-INF directory with MANIFEST to WEB-INF fixes the problem.

I don't think that it's correct that a WAR file should have its META-INF directory in its WEB-INF directory; the META-INF directory should be at the root of the WAR so I don't believe that this is the cause of the problem.

It could be that there's something in the MANIFEST.MF that's causing the problem, and that moving the META-INF directory hides the manifest and masks the problem.

I'm going to spend some time looking at this during the current 3 week sprint. I'll add any further updates to the JIRA.