Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 61B3D116DE for ; Fri, 5 Sep 2014 08:52:07 +0000 (UTC) Received: (qmail 71662 invoked by uid 500); 5 Sep 2014 08:47:00 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 70625 invoked by uid 500); 5 Sep 2014 08:47:00 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 69306 invoked by uid 99); 5 Sep 2014 08:35:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Sep 2014 08:35:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Sep 2014 08:35:18 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8B22123888A6; Fri, 5 Sep 2014 08:35:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1622639 - in /db/derby/code/branches/10.11: ./ java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java Date: Fri, 05 Sep 2014 08:35:16 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140905083516.8B22123888A6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Fri Sep 5 08:35:16 2014 New Revision: 1622639 URL: http://svn.apache.org/r1622639 Log: DERBY-6724: NPE if insert statement needs recompilation after having fired a trigger Merged revision 1622631 from trunk. Modified: db/derby/code/branches/10.11/ (props changed) db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java Propchange: db/derby/code/branches/10.11/ ------------------------------------------------------------------------------ Merged /db/derby/code/trunk:r1622631 Modified: db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java?rev=1622639&r1=1622638&r2=1622639&view=diff ============================================================================== --- db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java (original) +++ db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/InternalTriggerExecutionContext.java Fri Sep 5 08:35:16 2014 @@ -23,7 +23,6 @@ package org.apache.derby.impl.sql.execut import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Enumeration; import java.util.Hashtable; import java.util.Map; import java.util.Vector; @@ -233,20 +232,21 @@ class InternalTriggerExecutionContext protected void cleanup() throws StandardException { - lcc.popTriggerExecutionContext(this); + if (lcc != null) { + lcc.popTriggerExecutionContext(this); + } /* ** Explicitly close all result sets that we have ** given out to the user. */ - for (Enumeration e = resultSetVector.elements(); - e.hasMoreElements(); ) - { - java.sql.ResultSet rs = e.nextElement(); - try - { - rs.close(); - } catch (SQLException se) {} + if (resultSetVector != null) { + for (ResultSet rs : resultSetVector) { + try { + rs.close(); + } catch (SQLException se) { + } + } } resultSetVector = null; Modified: db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java?rev=1622639&r1=1622638&r2=1622639&view=diff ============================================================================== --- db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java (original) +++ db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StalePlansTest.java Fri Sep 5 08:35:16 2014 @@ -41,6 +41,14 @@ import org.apache.derbyTesting.junit.SQL * execution. */ public class StalePlansTest extends BaseJDBCTestCase { + /** + * The value of derby.language.stalePlanCheckInterval to use in this + * test. The default value is 100, but we use 10 to reduce the number + * of times the test has to execute statements to get to the desired + * state. + */ + private static final int STALE_PLAN_CHECK_INTERVAL = 10; + public StalePlansTest(String name) { super(name); } @@ -53,7 +61,8 @@ public class StalePlansTest extends Base Properties props = new Properties(); // Check for stale plans on every 10th execution (default 100) to // reduce the number of times we need to execute each statement. - props.setProperty("derby.language.stalePlanCheckInterval", "10"); + props.setProperty("derby.language.stalePlanCheckInterval", + String.valueOf(STALE_PLAN_CHECK_INTERVAL)); Test suite = new DatabasePropertyTestSetup( new BaseTestSuite(StalePlansTest.class), props, true); return new CleanDatabaseTestSetup(suite); @@ -296,4 +305,29 @@ public class StalePlansTest extends Base insert2.close(); ps.close(); } + + /** + * Regression test case for DERBY-6724, where an INSERT statement would + * fail with a NullPointerException if it had fired a trigger, and it + * was detected during execution that the statement plan was stale and + * had to be recompiled. + */ + public void testDerby6724() throws SQLException { + Statement s = createStatement(); + s.execute("create table d6724_t(x int)"); + s.execute("create trigger d6724_tr after insert on d6724_t values 1"); + s.execute("insert into d6724_t values 1"); + + // Before DERBY-6724 this statement would fail with an NPE in the + // (STALE_PLAN_CHECK_INTERVAL+1)'th execution. + PreparedStatement ps = prepareStatement( + "insert into d6724_t select * from d6724_t"); + for (int i = 0; i < STALE_PLAN_CHECK_INTERVAL + 1; i++) { + // Execute the statement and verify that the correct number of + // rows are inserted. The number doubles for each execution. + assertUpdateCount(ps, 1 << i); + } + + rollback(); + } }