ngk2009 / log4jdbc-log4j2

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

NullPointerException on empty result set running against Oracle #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
(log4jdbc-remix author here: sorry, I wrote this code . Consider this a 
placeholder issue. I will try to debug further and add a fix if possible)

On the surface of it, I think it looks like the result set meta data is not 
available on the empty result set. Probably behaviour specific to the oracle 
driver.

What steps will reproduce the problem?
1. Running a query against Oracle DB, with an empty result set 

What is the expected output? What do you see instead?
java.lang.NullPointerException (Integer columnCount=null -> int)
    at net.sf.log4jdbc.sql.resultsetcollector.DefaultResultSetCollector.getColumnCount(DefaultResultSetCollector.java:99)
    at net.sf.log4jdbc.sql.resultsetcollector.ResultSetCollectorPrinter.getResultSetToPrint(ResultSetCollectorPrinter.java:68)
    at net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator.resultSetCollected(Slf4jSpyLogDelegator.java:608)
    at net.sf.log4jdbc.sql.jdbcapi.ResultSetSpy.reportAllReturns(ResultSetSpy.java:104)
    at net.sf.log4jdbc.sql.jdbcapi.ResultSetSpy.reportReturn(ResultSetSpy.java:192)
    at net.sf.log4jdbc.sql.jdbcapi.ResultSetSpy.next(ResultSetSpy.java:1983)
...

What version of the product are you using? On what operating system?
groupId=org.bgee.log4jdbc-log4j2
artifactId=log4jdbc-log4j2-jdbc4
version=1.15

Centos 6.4

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

ojdbc*.jar Not sure which (underlying) driver I am using!

Original issue reported on code.google.com by tim.azzo...@gmail.com on 30 Oct 2013 at 11:59

GoogleCodeExporter commented 8 years ago
Facing same issue for DB2 database too.

<dependency>
  <groupId>org.bgee.log4jdbc-log4j2</groupId>
  <artifactId>log4jdbc-log4j2-jdbc4</artifactId>
  <version>1.15</version>
</dependency>

Original comment by tvseshag...@gmail.com on 19 Nov 2013 at 5:27

GoogleCodeExporter commented 8 years ago
We're facing the same issue. And the problem is indeed specific to the oracle 
driver which closes an empty result set the first time next() is called.

So is there an update on the status of this bug? It's preventing us from using 
JDBC logging effectively at the moment.

Original comment by gerritsc...@googlemail.com on 9 Dec 2013 at 9:42

GoogleCodeExporter commented 8 years ago
OK, I'll try to fix that today.

Original comment by frederic...@gmail.com on 9 Dec 2013 at 9:45

GoogleCodeExporter commented 8 years ago
I deployed a snapshot, could you please tell me all if it fixes your issues? If 
it doesn't, please provide me the exception stacktraces. 

<dependency>
  <groupId>org.bgee.log4jdbc-log4j2</groupId>
  <artifactId>log4jdbc-log4j2-jdbcXX</artifactId>
  <version>1.16-SNAPSHOT</version>
</dependency>

I haven't actually installed Oracle, nor DB2, but mocked the behavior of 
returning a null ResultSetMetaData. Given the error it generated, I am not 
totally convinced that the diagnostic is correct. So please keep me posted :)

Original comment by frederic...@gmail.com on 11 Dec 2013 at 12:24

GoogleCodeExporter commented 8 years ago
Just tried it out (on Oracle). The NPE is gone and result set logging is 
working.

Thanks a lot!

Original comment by gerritsc...@googlemail.com on 11 Dec 2013 at 7:35

GoogleCodeExporter commented 8 years ago
OK, the diagnostic was correct: because the ResultSetMetaData could not be 
acquired, the Integer columnCount in DefaultResultSetCollector was null; when 
calling getColumnCount, which returns an int, the auto boxing was generating 
the NPE. 

columnCount is now an int, with default value 0, and another attribute is used 
to ensure that the metadata are acquired only once. 

Artifact version 1.16 released. Closing this issue.

Original comment by frederic...@gmail.com on 12 Dec 2013 at 12:21