Derby
  1. Derby
  2. DERBY-3752

NullPointerException when inserting a blob in autocommit mode with an open result set

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 10.4.1.3
    • Fix Version/s: None
    • Component/s: JDBC
    • Urgency:
      Normal
    • Issue & fix info:
      Repro attached
    • Bug behavior facts:
      Deviation from standard

      Description

      Leaving a result set is left open in autocommit mode will trigger an NPE when attempting to insert a BLOB. Calling executeUpdate() to insert the BLOB appears to trigger a commit because of the open rs which in turn also frees the very BLOB you are trying to insert.

      To reproduce:

      Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
      Connection c =
      DriverManager.getConnection("jdbc:derby:db;create=true");
      Statement s = c.createStatement();
      try

      { s.execute("create table b (b blob)"); }

      catch (Exception e)

      { System.out.println(e); }

      s.executeQuery("VALUES 1"); // Closing this result set makes the problem disappear

      PreparedStatement ps = c.prepareStatement(
      "insert into b values ?");

      Blob b = c.createBlob();

      b.setBytes(1, new byte[0]);

      ps.setBlob(1, b);

      ps.executeUpdate();

      Call stack:
      Exception in thread "main" java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:95)
      at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:87)
      at org.apache.derby.impl.jdbc.Util.javaException(Util.java:244)
      at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:403)
      at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:346)
      at org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2179)
      at org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:81)
      at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1325)
      at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1652)
      at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:301)
      at repro.Main.main(Main.java:44)
      Caused by: java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
      at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:45)
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory40.java:119)
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:70)
      ... 10 more
      Caused by: java.lang.NullPointerException
      at org.apache.derby.impl.jdbc.LOBStreamControl.read(LOBStreamControl.java:271)
      at org.apache.derby.impl.jdbc.LOBInputStream.read(LOBInputStream.java:166)
      at java.io.FilterInputStream.read(FilterInputStream.java:66)
      at org.apache.derby.iapi.services.io.LimitInputStream.read(LimitInputStream.java:48)
      at org.apache.derby.iapi.types.RawToBinaryFormatStream.checkSufficientData(RawToBinaryFormatStream.java:219)
      at org.apache.derby.iapi.types.RawToBinaryFormatStream.read(RawToBinaryFormatStream.java:280)
      at org.apache.derby.impl.store.raw.data.MemByteHolder.write(MemByteHolder.java:146)
      at org.apache.derby.impl.store.raw.data.RememberBytesInputStream.fillBuf(RememberBytesInputStream.java:135)
      at org.apache.derby.impl.store.raw.data.StoredPage.logColumn(StoredPage.java:6156)
      at org.apache.derby.impl.store.raw.data.StoredPage.logRow(StoredPage.java:3970)
      at org.apache.derby.impl.store.raw.data.InsertOperation.writeOptionalDataToBuffer(InsertOperation.java:370)
      at org.apache.derby.impl.store.raw.data.InsertOperation.<init>(InsertOperation.java:115)
      at org.apache.derby.impl.store.raw.data.LoggableActions.actionInsert(LoggableActions.java:139)
      at org.apache.derby.impl.store.raw.data.BasePage.insertAllowOverflow(BasePage.java:763)
      at org.apache.derby.impl.store.raw.data.BasePage.insert(BasePage.java:653)
      at org.apache.derby.impl.store.access.heap.HeapController.doInsert(HeapController.java:307)
      at org.apache.derby.impl.store.access.heap.HeapController.insert(HeapController.java:575)
      at org.apache.derby.impl.sql.execute.RowChangerImpl.insertRow(RowChangerImpl.java:457)
      at org.apache.derby.impl.sql.execute.InsertResultSet.normalInsertCore(InsertResultSet.java:1011)
      at org.apache.derby.impl.sql.execute.InsertResultSet.open(InsertResultSet.java:487)
      at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:384)
      at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1235)
      ... 3 more

      1. Derby3752Repro.java
        0.9 kB
        Kristian Waagan

        Issue Links

          Activity

          Hide
          Kristian Waagan added a comment -

          Copied Dyre's repro code from the description into a file.

          Show
          Kristian Waagan added a comment - Copied Dyre's repro code from the description into a file.
          Hide
          Knut Anders Hatlen added a comment -

          Triaged for 10.5.2.

          Show
          Knut Anders Hatlen added a comment - Triaged for 10.5.2.
          Hide
          Dag H. Wanvik added a comment -

          Linking this issue to DERBY-3115; cf discussion of how to handle
          autocommit /closing of result sets there. I think at some point we
          should try to move in the direction of the JDBC specification and make
          ResultSet close drive autocommit.

          Show
          Dag H. Wanvik added a comment - Linking this issue to DERBY-3115 ; cf discussion of how to handle autocommit /closing of result sets there. I think at some point we should try to move in the direction of the JDBC specification and make ResultSet close drive autocommit.

            People

            • Assignee:
              Unassigned
              Reporter:
              Dyre Tjeldvoll
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development