arthurblake / log4jdbc

log4jdbc is a Java JDBC driver that can log SQL and/or JDBC calls (and optionally SQL timing information) for other JDBC drivers using the Simple Logging Facade For Java (SLF4J) logging system.
516 stars 147 forks source link

When use log4jdbc with Postgres jdbc4array type, will return null #81

Closed IamFive closed 8 years ago

IamFive commented 8 years ago

used driver version is :

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1205-jdbc41</version>
            <scope>compile</scope>
        </dependency>

used dbpool version

<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
    <version>2.2.5</version>
</dependency>

table created sql

create table test ( id serial4, tags varchar[]);

After serveral call, ResultSetSpy#getObject(int columnIndex) will return null, i am not sure why, still debug it. if I stop spy the datasource, everything works fine.

IamFive commented 8 years ago

The situation is wired, it seems the bug happens in realResultSet.getObject(), but if i remove log4jdbc spy, everything works.

IamFive commented 8 years ago

I find out the reason, I have create an [issue|https://github.com/pgjdbc/pgjdbc/issues/540] for postgres-driver project, could check the detail there.

the bug code position for log4jdbc is: net.sf.log4jdbc.sql.resultsetcollector.ResultSetCollectorPrinter#getResultSetToPrint(ResultSetCollector resultSetCollector) at line 80, add a validate before call length()

if (v != null) {
      String asStr = v.toString();
      if(asStr != null) {
              int length = asStr.length();
              if (length > maxLength[colIndex]) {
                  maxLength[colIndex] = length;
              }
      }
 }

image

IamFive commented 8 years ago

issue has been fix in newest version