Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 73059 - Shutdown hook throws NoClassDefFoundError
Summary: Shutdown hook throws NoClassDefFoundError
Status: RESOLVED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: platform-runtime-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-01 10:55 EDT by Rob Grzywinski CLA
Modified: 2004-09-01 12:02 EDT (History)
0 users

See Also:


Attachments
Three source files (in a zip) that exhibit the shutdown bug (1.74 KB, application/octet-stream)
2004-09-01 10:58 EDT, Rob Grzywinski CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Grzywinski CLA 2004-09-01 10:55:02 EDT
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.
Comment 1 Rob Grzywinski CLA 2004-09-01 10:58:47 EDT
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.
Comment 2 Rob Grzywinski CLA 2004-09-01 11:18:30 EDT
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.
Comment 3 Rafael Chaves CLA 2004-09-01 11:37:59 EDT
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?
Comment 4 Rob Grzywinski CLA 2004-09-01 11:45:37 EDT
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.
Comment 5 Rafael Chaves CLA 2004-09-01 12:02:03 EDT
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.