Bug 57783 - NPE in SlowQueryReport - getQueryStats() returning null
Summary: NPE in SlowQueryReport - getQueryStats() returning null
Status: RESOLVED FIXED
Alias: None
Product: Tomcat Modules
Classification: Unclassified
Component: jdbc-pool (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-31 19:33 UTC by Drew Mazurek
Modified: 2015-06-23 07:27 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Drew Mazurek 2015-03-31 19:33:19 UTC
I'm running Tomcat 7.0.52 (7.0.52-1ubuntu0.1) with jdbc-pool and I see this exception in catalina.out somewhat frequently:

Mar 30, 2015 11:44:44 PM org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport createStatement
WARNING: Unable to create statement proxy for slow query report.
java.lang.NullPointerException
        at org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport.prepareStatement(SlowQueryReport.java:122)

As far as I can tell, it appears unrelated to #51582. In this case, some condition causes getQueryStats() to return null:

    public void prepareStatement(String sql, long time) {
        QueryStats qs = getQueryStats(sql);
        qs.prepare(time); // <--- LINE 122
    }

Please let me know if you need any more info.
Comment 1 Keiichi Fujino 2015-06-23 07:27:41 UTC
Thanks for the report.

I examined the code of SlowQueryReport.
There were two problems that cause NPE.

The first is
Because SlowQueryReport#removeOldest has not been implemented correctly,
If multiple threads invoke the same query at the same time,
It is possible to return null.

The second is
If this Interceptor has executed a connection that had been closed by the removeAbandoned,
It is possible to return null.

The former issue has been fixed in r1686791 and r1686792, the latter issue has been fixed in r1686975 and r1686976.
These revisions are scheduled to be included in the release of Tomcat8.0.24, Tomcat 7.0.63 or later.