Menu

#15 NPE in JDBCMonProxy on SQLDeArgMon.add()

open
nobody
None
5
2012-11-12
2012-11-12
Anonymous
No

Hi!
I use JAMon 2.73 and occasionally get following Exception:
java.lang.NullPointerException
at com.jamonapi.proxy.JDBCMonProxy$SQLDeArgMon.access$300(JDBCMonProxy.java:224)
at com.jamonapi.proxy.JDBCMonProxy.invoke(JDBCMonProxy.java:139)

It is caused by a web application (thus multi-threaded use) with stand JDBC-Connection-Proxy and I get this exception roughly 300 times from 7000 SQL calls.

Reason is in source line 139 ("sqlMon.add(executionTime).appendDetails(stackTrace).stop()"): sqlMon is null (access$300 is the Java compiler generated add-delegate to the static inner class).
Possible root cause: An exception is thrown in isStatementObject() or constructor SQLDeArgMon() (source lins 74 - 76), so the variable sqlMon remains null. Or: statementsMap does not contain a monitor (line 79).

(I could add logging to get more details, but changing jamon.jar requires a production server restart... Maybe I will do it.)

Quick solution (this is only a hack!): Add "sqlMon != null" before the call in line 139.

Discussion

  • Nobody/Anonymous

    Additional info:
    The source line sqlMon=(SQLDeArgMon) statementsMap.get(getMonitoredObject())
    sometimes results in a null object and causes an NPE then.
    getMonitoredObject() results in a valid object (oracle.jdbc.driver.T4CPreparedStatement), so storage in the Map is causing the problem.
    The null objects are not there from the beginning (i.e. server start), they only occur after some time. Maybe the used WeakHashMap is the problem, together with pooling of Connection and PreparedStatement.

    I simply added some "== null" tests to avoid the NPE. But this is certainly no real solution!

     
  • Nobody/Anonymous

    The patch file for my changes (I could not attach the file - maybe because of missing login?), some debug output is commented out:

    56a57
    > Throwable safedThrowable = null;
    80,85c81,89
    < statementReuseCounter=sqlMon.incrementCounter();// increment the reuse counter.
    < if (isSQLSummaryEnabled)
    < MonitorFactory.add("MonProxy-SQL-PreparedStatement Reuse","count", 2*statementReuseCounter);// to get the average to be accurate multiply by 2
    <
    < actualSQL=getSQL(sqlMon.getSQL());// in the case of a preparedStatement the actual sql includes question marks.
    <
    ---
    > if (sqlMon != null) { // sometimes (because of WeakHashMap and pooling??) this is null
    > statementReuseCounter=sqlMon.incrementCounter();// increment the reuse counter.
    > if (isSQLSummaryEnabled)
    > MonitorFactory.add("MonProxy-SQL-PreparedStatement Reuse","count", 2*statementReuseCounter);// to get the average to be accurate multiply by 2
    > actualSQL=getSQL(sqlMon.getSQL());// in the case of a preparedStatement the actual sql includes question marks.
    > } else {
    > //System.out.println("JDBCMonProxy: sqlMon == null after stmtMap.get(" + getMonitoredObject() + ")");
    > actualSQL = "NPE: sqlMon == null";
    > }
    89c93
    < if (isSQLSummaryEnabled)
    ---
    > if (isSQLSummaryEnabled && sqlMon != null)
    126a131
    > safedThrowable = e;
    138,139c143,155
    < if (isSQLSummaryEnabled)
    < sqlMon.add(executionTime).appendDetails(stackTrace).stop();
    ---
    > if (isSQLSummaryEnabled) {
    > if (sqlMon != null) {
    > sqlMon.add(executionTime).appendDetails(stackTrace).stop();
    > } else {
    > /*
    > System.out.println("JDBCMonProxy: sqlMon == null");
    > if (safedThrowable != null) {
    > System.out.println(" Throwable: " + safedThrowable);
    > safedThrowable.printStackTrace();
    > }
    > */
    > }
    > }

     
  • Nobody/Anonymous

    I found the service to be a great deal. The Lida lida daidaihua makes me less hungry and the fat burn is helping me be rid of my flab. The instructions that came with it told me that getting my eating in hand was necessary for a winning approach. I really took that to heart and have been using a lot more discipline when I am eating and the hoodia makes all that easier. I am doing sit ups and taking the service every day and so far, My flab is disappearing. I dont own a working scale but almost certainly that things are improving podedsja.
    pai you guo pills http://www.2daydietbase.com/pai-you-guo-capsule-p-13.html

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.