brunorozendo / log4jdbc-log4j2

Automatically exported from code.google.com/p/log4jdbc-log4j2
48 stars 39 forks source link

Fix NPE in DefaultResultSetCollector #39

Closed felipecsl closed 6 years ago

felipecsl commented 6 years ago

We recently started seeing a NullPointerException in DefaultResultSetCollector#loadMetaDataIfNeeded on this line:

String table = metaData.getTableName(column).toLowerCase()

Here is the relevant stacktrace:

java.lang.NullPointerException: null
    at net.sf.log4jdbc.sql.resultsetcollector.DefaultResultSetCollector.loadMetaDataIfNeeded
    at net.sf.log4jdbc.sql.resultsetcollector.DefaultResultSetCollector.loadMetaDataIfNeeded
    at net.sf.log4jdbc.sql.jdbcapi.ResultSetSpy.loadMetaDataIfNeeded
    at net.sf.log4jdbc.sql.jdbcapi.ResultSetSpy.close
    at org.skife.jdbi.v2.Cleanables$ResultSetCleanable.cleanup
    at org.skife.jdbi.v2.BaseStatement$StatementCleaningCustomizer.cleanup
    at org.skife.jdbi.v2.BaseStatement.cleanup
    at org.skife.jdbi.v2.GeneratedKeys.first
    at org.skife.jdbi.v2.sqlobject.ResultReturnThing$SingleValueResultReturnThing.result
    at org.skife.jdbi.v2.sqlobject.UpdateHandler$1.value
    at org.skife.jdbi.v2.sqlobject.UpdateHandler.invoke
    at org.skife.jdbi.v2.sqlobject.SqlObject.invoke
    at org.skife.jdbi.v2.sqlobject.SqlObject$3.intercept

I'm not entirely sure what triggered this issue in the first place, it seems like ResultSetMetaData#getTableName started returning null which caused the NPE. Guarding that block with a null check seems to fix the issue.

Please note that my IDE made other (unrelated) changes to the file due to inconsistent line breaks and trailing spaces. You can ignore that. Actual change is on line 174