Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 312526

Summary: If I create my own shutdown hook which calls server.stop(), it can throw ExceptionInInitializerError.
Product: [RT] Jetty Reporter: Robert Tupelo-Schneck <schneck>
Component: serverAssignee: Greg Wilkins <gregw>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: jetty-inbox, mgorovoy
Version: unspecified   
Target Milestone: 7.0.2.RC0   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Bug Depends on: 311554    
Bug Blocks:    

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