| 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: | server | Assignee: | 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: | |||
Duplicate of #311554 Added double exception handling for ShutdownThread if shutdown already commenced. r1774 |
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.