Bug 62792

Summary: Race condition NullpointerException in JspServletWrapper
Product: Tomcat 9 Reporter: Julien Béti <julien>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 9.0.12   
Target Milestone: -----   
Hardware: PC   
OS: Linux   
Bug Depends on: 62603    
Bug Blocks:    

Description Julien Béti 2018-10-02 09:13:04 UTC
We do have the following NullPointerException in Tomcat 9.0.12 in production mode, with checkinterval:

org.apache.jasper.JasperException: java.lang.NullPointerException
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:498)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:580)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:516)
        at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:868)

This issue seems to have been introduced by bug 62603, where getServlet can now return null.

getReloadInternal seems to return false without theServlet being properly initialized.

It seems it can occurs if firstTime is false, reload is true and ctxt.getRuntimeContext().isCompileCheckInProgress() is true.
Comment 1 Julien Béti 2018-10-02 09:14:38 UTC
Sorry, the caused-by part of the trace was missing:

Caused by: java.lang.NullPointerException: null
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:458)
        ... 74 common frames omitted
Comment 2 Julien Béti 2018-10-02 09:38:33 UTC
I would suggest to keep the "if(reload)" outside the synchronized block, and check again inside with "getReloadInternal()"

Something like

if(reload) {
   synchronized (this) {
    if(getReloadInternal()) {
Comment 3 Mark Thomas 2018-10-02 20:30:34 UTC
The problem is a little broader than described here. The duplicate has a full description and the discussion of the proposed fix.

*** This bug has been marked as a duplicate of bug 62757 ***