Bug 62792 - Race condition NullpointerException in JspServletWrapper
Summary: Race condition NullpointerException in JspServletWrapper
Status: RESOLVED DUPLICATE of bug 62757
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 9.0.12
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
Depends on: 62603
  Show dependency tree
Reported: 2018-10-02 09:13 UTC by Julien Béti
Modified: 2018-10-02 20:30 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
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 ***