db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1823037 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java
Date Sat, 03 Feb 2018 16:09:48 GMT
Author: bpendleton
Date: Sat Feb  3 16:09:48 2018
New Revision: 1823037

URL: http://svn.apache.org/viewvc?rev=1823037&view=rev
Log:
DERBY-6981: NullPointerException when re-executing PreparedStatement query.

TableScanResultSet's past2FutureTbl is a hash table containing updated
rows that are thrown into the future direction of the index scan, so
that the scan knows it's seen these rows already and should skip them
subsequently.

When the TableScanResultSet.close() method was called, it was closing the
past2FutureTbl, but not clearing the pointer, which caused the lazy
initialization of the past2FutureTbl to be incorrectly performed the
next time the same TableScanResultSet was opened and scanned, resulting
in the NullPointerException in the underlying BackingStoreHashtable code
in that second scan.

The fix is to clear the old instance and freshly initialize a new instance,
each time the TableScanResultSet is closed and reopened.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java?rev=1823037&r1=1823036&r2=1823037&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
Sat Feb  3 16:09:48 2018
@@ -625,6 +625,7 @@ class TableScanResultSet extends ScanRes
             if (past2FutureTbl != null)
             {
                 past2FutureTbl.close();
+                past2FutureTbl = null;
             }
 	    }
 		else

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java?rev=1823037&r1=1823036&r2=1823037&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java
Sat Feb  3 16:09:48 2018
@@ -26,6 +26,8 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.Date;
 import junit.framework.Test;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -717,4 +719,40 @@ public class UpdatableResultSetTest exte
         return stmt.executeQuery("select " + colName +
                 " from UpdateTestTableResultSet where sno = " + key);
     }
+
+    public void testDerby6981()
+        throws SQLException
+    {
+        Statement stmt = createStatement();
+        stmt.executeUpdate("CREATE TABLE TEST1 " +
+            "(ID int PRIMARY KEY NOT NULL,LASTUPDATE timestamp)");
+        PreparedStatement ps = prepareStatement(
+            "SELECT id, LASTUPDATE FROM test1 WHERE id = ? " +
+                    "FOR UPDATE OF id, LASTUPDATE ",
+            ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+
+        long newDate = new Date().getTime();
+
+        for (int i = 0; i < 3; i++)
+        {
+            ps.setInt(1, 3);
+            ResultSet rs = ps.executeQuery();
+            if (!rs.next())
+            {
+                rs.moveToInsertRow();
+                rs.updateInt(1, 3);
+                rs.updateTimestamp(2, new Timestamp(newDate));
+                rs.insertRow();
+            }
+            else
+            {
+                rs.updateInt(1, 3);
+                rs.updateTimestamp(2, new Timestamp(newDate));
+                rs.updateRow();
+            }
+            rs.close();
+        }
+        stmt.close();
+        ps.close();
+    }
 }



Mime
View raw message