Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 312526 - If I create my own shutdown hook which calls server.stop(), it can throw ExceptionInInitializerError.
Summary: If I create my own shutdown hook which calls server.stop(), it can throw Exce...
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 minor (vote)
Target Milestone: 7.0.2.RC0   Edit
Assignee: Greg Wilkins CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 311554
Blocks:
  Show dependency tree
 
Reported: 2010-05-11 23:57 EDT by Robert Tupelo-Schneck CLA
Modified: 2010-05-14 02:48 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Tupelo-Schneck CLA 2010-05-11 23:57:43 EDT
Build Identifier: 7.0.2.v20100331

Server#stop() calls ShutdownThread.deregister(this).  This may be the first time the JVM sees "ShutdownThread", which adds a shutdown hook.  If we do this inside of a shutdown hook, an ExceptionInInitializerError is thrown.

It's easy enough to get the server itself to put in a shutdown hook which initializes ShutdownThread early enough that this doesn't happen.  But, it shouldn't happen anyway.

Reproducible: Always

Steps to Reproduce:
I create a very small embedded server:
        HandlerCollection handlers = new HandlerCollection();
        ServletContextHandler root = new ServletContextHandler(handlers, "/", ServletContextHandler.NO_SESSIONS|ServletContextHandler.NO_SECURITY);
        root.addServlet(new ServletHolder(new MyServlet()), "/*");
        Server server = new Server(main.options.port);
        server.setHandler(handlers);
        server.start();

Then I register my own shutdown hook, which among other things calls server.stop().

It throws ExceptionInInitializerError when it sees a static reference to ShutdownThread for the first time.
Comment 1 Greg Wilkins CLA 2010-05-14 02:44:15 EDT
Duplicate of #311554
Comment 2 Greg Wilkins CLA 2010-05-14 02:48:38 EDT
Added double exception handling for ShutdownThread if 
shutdown already commenced.

r1774