Bug 45591 - NullPointerException during shutdown in JKMain.pause()
NullPointerException during shutdown in JKMain.pause()
Status: RESOLVED FIXED
Product: Tomcat 5
Classification: Unclassified
Component: Connector:AJP
5.5.20
PC Windows XP
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2008-08-07 12:35 UTC by Matt Passell
Modified: 2008-08-27 13:58 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Passell 2008-08-07 12:35:38 UTC
On startup, if Tomcat discovers that the main port is already bound to another process, it fails and tries to execute the shutdown code.  In some situations (I'm not sure which), the org.apache.jk.server.JKMain instance variable wEnv is null at this point, which causes a NullPointerException when JKMain.pause() is called (see stacktrace below).  Since this is occurring within a shutdown hook thread, it can result in a dirty shutdown of the JVM.  I've observed this with Tomcat 5.5.20, but I looked over the code in 5.5.26 and it looks like the same problem is still present.

Fortunately, the solution is very simple.  Just add the following if test at the beginning of JKMain.pause():

        if (wEnv == null) {
          return;
        }


Stacktrace:
SEVERE: StandardServer.await: create[8006]: 
java.net.BindException: Address already in use: JVM_Bind
	at java.net.PlainSocketImpl.socketBind(Native Method)
	at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
	at java.net.ServerSocket.bind(ServerSocket.java:319)
	at java.net.ServerSocket.<init>(ServerSocket.java:185)
	at org.apache.catalina.core.StandardServer.await(StandardServer.java:372)
	at org.apache.catalina.startup.Catalina.await(Catalina.java:615)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:575)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Aug 7, 2008 3:25:34 PM org.apache.coyote.http11.Http11BaseProtocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8000
Aug 7, 2008 3:25:34 PM org.apache.catalina.connector.Connector pause
SEVERE: Protocol handler pause failed
java.lang.NullPointerException
	at org.apache.jk.server.JkMain.pause(JkMain.java:678)
	at org.apache.jk.server.JkCoyoteHandler.pause(JkCoyoteHandler.java:162)
	at org.apache.catalina.connector.Connector.pause(Connector.java:1031)
	at org.apache.catalina.core.StandardService.stop(StandardService.java:491)
	at org.apache.catalina.core.StandardServer.stop(StandardServer.java:743)
	at org.apache.catalina.startup.Catalina.stop(Catalina.java:601)
	at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:644)
Comment 1 Mark Thomas 2008-08-08 07:36:34 UTC
Thanks for the report and patch. I have committed a slightly different version to trunk and proposed it for 6.0.x and 5.5.x
Comment 2 Matt Passell 2008-08-08 08:23:53 UTC
(In reply to comment #1)
> Thanks for the report and patch. I have committed a slightly different version
> to trunk and proposed it for 6.0.x and 5.5.x


Thanks!

--Matt
Comment 3 Mark Thomas 2008-08-13 15:35:47 UTC
This has been fixed in 6.0.x and will be included in 6.0.19 onwards.
Comment 4 Mark Thomas 2008-08-27 13:58:02 UTC
This has been fixed in 5.5.x and will be included in 5.5.27 onwards.