Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-3799

NullPointerException when accessing a clob through a pooled connection

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.4.1.3, 10.5.1.1
    • Fix Version/s: 10.4.2.0, 10.5.1.1
    • Component/s: Network Client
    • Labels:
      None
    • Environment:

      Description

      After returning a pooled connection to the pool and getting it again a NullPointerException is thrown when a clob field is accessed again. This may be related to the following post: http://mail-archives.apache.org/mod_mbox/db-derby-user/200803.mbox/%3C47CD3431.5020205@sun.com%3E

      Here is the stack trace:
      java.lang.NullPointerException
      at org.apache.derby.client.am.PreparedStatement.setIntX(Unknown Source)
      at org.apache.derby.client.am.CallableLocatorProcedures.clobGetLength(Unknown Source)
      at org.apache.derby.client.am.Clob.getLocatorLength(Unknown Source)
      at org.apache.derby.client.am.Lob.sqlLength(Unknown Source)
      at org.apache.derby.client.am.Clob.length(Unknown Source)
      at org.apache.derby.client.am.Cursor.getString(Unknown Source)
      at org.apache.derby.client.am.ResultSet.getString(Unknown Source)
      at derbyerr.Main.main(Main.java:65)

      Here is the code to reproduce the problem:

      package derbyerr;

      import java.sql.Connection;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import javax.sql.PooledConnection;
      import org.apache.derby.jdbc.ClientConnectionPoolDataSource;

      public class Main {

      public static void main (String[] args) {
      org.apache.derby.tools.sysinfo.main (args) ;

      ClientConnectionPoolDataSource creator = new ClientConnectionPoolDataSource () ;
      // There should be an empty db named testdb
      creator.setDatabaseName ("testdb") ;

      try {
      PooledConnection pc = creator.getPooledConnection () ;

      Connection c = pc.getConnection () ;
      PreparedStatement ps ;
      ResultSet rs ;
      String s ;

      // Drop the table "test", if it exsists
      try

      { ps = c.prepareStatement ("drop table test") ; ps.execute () ; ps.close () ; }

      catch (Exception e) {
      }

      // Create a test table with a clob field
      ps = c.prepareStatement ("create table test (pkey varchar(255) not null primary key, value clob)") ;
      ps.execute () ;
      ps.close () ;

      // Insert a record
      ps = c.prepareStatement ("insert into test values ('123', 'abc')") ;
      ps.execute () ;
      ps.close () ;

      // Query the record and...
      ps = c.prepareStatement ("select * from test") ;
      rs = ps.executeQuery () ;
      rs.next () ;
      // ...access the clob field - this works
      s = rs.getString (2) ;
      assert s.equals ("abc") ;
      rs.close () ;
      ps.close () ;

      // Simulate connection pooling: close the connection and get it again
      c.close () ;
      c = pc.getConnection () ;

      // Now again query the record...
      ps = c.prepareStatement ("select * from test") ;
      rs = ps.executeQuery () ;
      rs.next () ;
      // ...and access the clob - this fails
      s = rs.getString (2) ;
      assert s.equals ("abc") ;
      rs.close () ;
      ps.close () ;

      } catch (Exception e)

      { e.printStackTrace () ; }

      }

      }

        Attachments

        1. derby-3799-1a-checkIfClosed.diff
          10 kB
          Kristian Waagan

          Activity

            People

            • Assignee:
              kristwaa Kristian Waagan
              Reporter:
              rlovec Ralf Lovec
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: