Community
Participate
Working Groups
I have a class that registers a shutdown hook (Runtime.getRuntime ().addShutdownHook()) that references a class that is never loaded until the shutdown hook is executed. Eclipse throws a NoClassDefFoundError from org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass() (from org.eclipse.core.runtime.adaptor.EclipseClassLoader). As long as I don't screw up horribly, an attachment that highlights the problem should be available. I should note that I am attempting to use a third party library that contains the shutdown hook. The source attached only highlights the problem to that it can be tested. I mention this since a solution of "just move the code to a dispose() method" is not acceptible.
Created attachment 14325 [details] Three source files (in a zip) that exhibit the shutdown bug The zip contains three source files: TestShutdownHookView -- the ViewPart ClassWithShutdownHook -- the class that creates the shutdown hook NotLoadedUntilShutdown -- the class that's not loaded until the shutdown hook is called Unfortunately you will need to create your own plugin to use / test these classes.
I should mention that a workaround does exist. As long as the class (in this case NotLoadedUntilShutdown) is loaded before the shutdown hook is called then the defect does not occur. The class can be artifically loaded through the ClassLoader directly or indirectly by calling a method on the class.
After your plug-in has been stopped during shutdown, class loading will be disabled. So when the shutdown hook gets executed, and needs to load more classes, it will fail. This is to protect your code from being run when your plug-in is not longer active. One way to avoid this problem is to disable auto-activation. See: http://help.eclipse.org/help30/topic/org.eclipse.pde.doc.user/guide/pde_manifest_runtime.htm Do the classes being loaded during shutdown come from the 3rd party library or they are yours?
The shutdown hook and related classes are all in the 3rd party library unfortunately. Thank you for the link. I suppose that this can be marked "invalid" or "wontfix" given the two different workarounds with disabling auto-activation being the perferred route. Is there a reference for implications for disabling auto-activation? Thank you.
Eclipse ensures Plugin.startup is called before any code and your plug-in runs. Most plug-ins rely on that fact. Since you are deplying a third-party library which does not even know what Eclipse is, this is not an issue. BTW: in your case, I would rather leave the 3rd-party library as a separate plug-in, instead for selectively disabling auto-activation in the plug-in that contains your own code.