Derby
  1. Derby
  2. DERBY-4779

NPE while inserting into a table which has a generated column and an insert trigger

    Details

    • Urgency:
      Normal
    • Issue & fix info:
      High Value Fix, Repro attached

      Description

      The following script generates an NPE on the concluding insert:

      connect 'jdbc:derby:memory:dummy;create=true';

      create function getRegion( v int )
      returns varchar( 20 )
      language java parameter style java deterministic no sql
      external name 'java.lang.Integer.toString'
      ;

      create table orders
      (
      orderID bigint primary key,
      salesPrice int not null,
      region generated always as ( getRegion( salesPrice ) )
      )
      ;
      create table dummy( a int );

      create trigger newOrderTrigger
      after insert on orders
      for each row
      insert into dummy( a ) values ( 1 )
      ;

      insert into orders( orderID, salesPrice ) values ( 1, 2 )
      ;

      ------------------------

      Here is the NPE:

      java.lang.NullPointerException
      at org.apache.derby.impl.sql.execute.DMLWriteResultSet.objectifyStreams(Unknown Source)
      at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(Unknown Source)
      at org.apache.derby.impl.sql.execute.InsertResultSet.open(Unknown Source)
      at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
      at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
      at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
      at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
      at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
      at org.apache.derby.impl.tools.ij.ij.executeImmediate(Unknown Source)
      at org.apache.derby.impl.tools.ij.utilMain.doCatch(Unknown Source)
      at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(Unknown Source)
      at org.apache.derby.impl.tools.ij.utilMain.go(Unknown Source)
      at org.apache.derby.impl.tools.ij.Main.go(Unknown Source)
      at org.apache.derby.impl.tools.ij.Main.mainCore(Unknown Source)
      at org.apache.derby.impl.tools.ij.Main.main(Unknown Source)
      at org.apache.derby.tools.ij.main(Unknown Source)

      1. testreport.txt
        1 kB
        Siddharth Srivastava
      2. test1.diff
        7 kB
        Siddharth Srivastava
      3. derby-4779_10_5_diff.txt
        6 kB
        Kathey Marsden
      4. d4779.diff
        2 kB
        Siddharth Srivastava
      5. d4779.diff
        5 kB
        Siddharth Srivastava

        Issue Links

          Activity

          Hide
          Siddharth Srivastava added a comment -

          Updating the error log to include the line numbers where the error occurs (previous log consisted of UNKNOWN SOURCE in place of linu numbers)

          java.lang.NullPointerException
          at org.apache.derby.impl.sql.execute.DMLWriteResultSet.objectifyStreams(DMLWriteResultSet.java:155)
          at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:135)
          at org.apache.derby.impl.sql.execute.InsertResultSet.open(InsertResultSet.java:504)
          at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:436)
          at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:317)
          at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1242)
          at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:630)
          at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:559)
          at org.apache.derby.impl.tools.ij.ij.executeImmediate(ij.java:367)
          at org.apache.derby.impl.tools.ij.utilMain.doCatch(utilMain.java:521)
          at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(utilMain.java:363)
          at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:261)
          at org.apache.derby.impl.tools.ij.Main.go(Main.java:229)
          at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:184)
          at org.apache.derby.impl.tools.ij.Main.main(Main.java:75)
          at org.apache.derby.tools.ij.main(ij.java:59)
          at org.apache.derby.iapi.tools.run.main(run.java:53)

          Show
          Siddharth Srivastava added a comment - Updating the error log to include the line numbers where the error occurs (previous log consisted of UNKNOWN SOURCE in place of linu numbers) java.lang.NullPointerException at org.apache.derby.impl.sql.execute.DMLWriteResultSet.objectifyStreams(DMLWriteResultSet.java:155) at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:135) at org.apache.derby.impl.sql.execute.InsertResultSet.open(InsertResultSet.java:504) at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:436) at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:317) at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1242) at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:630) at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:559) at org.apache.derby.impl.tools.ij.ij.executeImmediate(ij.java:367) at org.apache.derby.impl.tools.ij.utilMain.doCatch(utilMain.java:521) at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(utilMain.java:363) at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:261) at org.apache.derby.impl.tools.ij.Main.go(Main.java:229) at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:184) at org.apache.derby.impl.tools.ij.Main.main(Main.java:75) at org.apache.derby.tools.ij.main(ij.java:59) at org.apache.derby.iapi.tools.run.main(run.java:53)
          Hide
          Siddharth Srivastava added a comment -

          The patch for this issue is attached. (The regression tests are going on)

          The NPE doesn't occur after the concluding insert anymore.

          Verified that the trigger is fired after insert:

          ij> select * from dummy;
          A
          -----------
          1

          1 row selected

          Show
          Siddharth Srivastava added a comment - The patch for this issue is attached. (The regression tests are going on) The NPE doesn't occur after the concluding insert anymore. Verified that the trigger is fired after insert: ij> select * from dummy; A ----------- 1 1 row selected
          Hide
          Siddharth Srivastava added a comment -

          Regression Test Update: The patch has passed the regression test.

          Show
          Siddharth Srivastava added a comment - Regression Test Update: The patch has passed the regression test.
          Hide
          Rick Hillegas added a comment -

          Thanks for the patch, Siddharth. It looks good to me. Just needs a regression test case--you might want to add a test case to GeneratedColumnsTest. Thanks!

          Show
          Rick Hillegas added a comment - Thanks for the patch, Siddharth. It looks good to me. Just needs a regression test case--you might want to add a test case to GeneratedColumnsTest. Thanks!
          Hide
          Siddharth Srivastava added a comment -

          Hi

          I have added the test for this test.
          I tried to maintain the existing structure, but I get the following error when I run the test:

          There was 1 failure:
          1) test_007_basicTriggers(org.apache.derbyTesting.functionTests.tests.lang.Gener
          atedColumnsTest)junit.framework.AssertionFailedError
          at org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsHelp
          er.assertResults(GeneratedColumnsHelper.java:379)
          at org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsTest
          .assertTriggerStatus(GeneratedColumnsTest.java:5575)
          at org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsTest
          .test_007_basicTriggers(GeneratedColumnsTest.java:1037)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at org.apache.derbyTesting.junit.BaseTestCase.runBare(BaseTestCase.java:
          112)
          at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
          at junit.extensions.TestSetup$1.protect(TestSetup.java:21)
          at junit.extensions.TestSetup.run(TestSetup.java:25)
          at org.apache.derbyTesting.junit.BaseTestSetup.run(BaseTestSetup.java:57
          )
          at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
          at junit.extensions.TestSetup$1.protect(TestSetup.java:21)
          at junit.extensions.TestSetup.run(TestSetup.java:25)

          FAILURES!!!

          How can I verify the contents of the table this way ?

          Show
          Siddharth Srivastava added a comment - Hi I have added the test for this test. I tried to maintain the existing structure, but I get the following error when I run the test: There was 1 failure: 1) test_007_basicTriggers(org.apache.derbyTesting.functionTests.tests.lang.Gener atedColumnsTest)junit.framework.AssertionFailedError at org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsHelp er.assertResults(GeneratedColumnsHelper.java:379) at org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsTest .assertTriggerStatus(GeneratedColumnsTest.java:5575) at org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsTest .test_007_basicTriggers(GeneratedColumnsTest.java:1037) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at org.apache.derbyTesting.junit.BaseTestCase.runBare(BaseTestCase.java: 112) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24) at junit.extensions.TestSetup$1.protect(TestSetup.java:21) at junit.extensions.TestSetup.run(TestSetup.java:25) at org.apache.derbyTesting.junit.BaseTestSetup.run(BaseTestSetup.java:57 ) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24) at junit.extensions.TestSetup$1.protect(TestSetup.java:21) at junit.extensions.TestSetup.run(TestSetup.java:25) FAILURES!!! How can I verify the contents of the table this way ?
          Hide
          Rick Hillegas added a comment -

          Hi Siddharth,

          You seem to be calling assertTriggerStatus() in order to confirm the behavior of the table and trigger you added. That method verifies the behavior of triggers which call the report_proc procedure. Your trigger doesn't call report_proc. Instead, your trigger just inserts into a dummy table. To verify the operation of your trigger, you need to verify the contents of the dummy table. To fix the test, I would do one of the following:

          1) Rewrite your trigger so that it calls report_proc like the other triggers in test_007_basicTriggers().

          2) Or rewrite your assertion to invoke assertResults() rather than assertTriggerStatus().

          Hope this helps,
          -Rick

          Show
          Rick Hillegas added a comment - Hi Siddharth, You seem to be calling assertTriggerStatus() in order to confirm the behavior of the table and trigger you added. That method verifies the behavior of triggers which call the report_proc procedure. Your trigger doesn't call report_proc. Instead, your trigger just inserts into a dummy table. To verify the operation of your trigger, you need to verify the contents of the dummy table. To fix the test, I would do one of the following: 1) Rewrite your trigger so that it calls report_proc like the other triggers in test_007_basicTriggers(). 2) Or rewrite your assertion to invoke assertResults() rather than assertTriggerStatus(). Hope this helps, -Rick
          Hide
          Siddharth Srivastava added a comment -

          The attached diff contains the fix and the test for the same.

          Show
          Siddharth Srivastava added a comment - The attached diff contains the fix and the test for the same.
          Hide
          Siddharth Srivastava added a comment -

          Update: The patch has passed the regression tests

          Show
          Siddharth Srivastava added a comment - Update: The patch has passed the regression tests
          Hide
          Rick Hillegas added a comment -

          Thanks for the revised patch with test, Siddharth. Looks good to me. Committed at subversion revision 1140222. Regression tests passed cleanly for me except for a ping test problem which does not seem to be related to your patch:

          1) testPingWithWrongHost(org.apache.derbyTesting.functionTests.tests.derbynet.NetworkServerControlClientCommandTest)junit.framework.AssertionFailedError: Could not find expectedString:Unable to find host in output:Mon Jun 27 07:21:11 PDT 2011 : Could not connect to Derby Network Server on host nothere, port 1527: Operation timed out

          at org.apache.derbyTesting.junit.BaseTestCase.assertExecJavaCmdAsExpected(BaseTestCase.java:516)
          at org.apache.derbyTesting.functionTests.tests.derbynet.NetworkServerControlClientCommandTest.assertFailedPing(NetworkServerControlClientCommandTest.java:147)
          at org.apache.derbyTesting.functionTests.tests.derbynet.NetworkServerControlClientCommandTest.testPingWithWrongHost(NetworkServerControlClientCommandTest.java:112)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at org.apache.derbyTesting.junit.BaseTestCase.runBare(BaseTestCase.java:112)
          at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
          at junit.extensions.TestSetup$1.protect(TestSetup.java:21)
          at junit.extensions.TestSetup.run(TestSetup.java:25)
          at org.apache.derbyTesting.junit.BaseTestSetup.run(BaseTestSetup.java:57)
          at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
          at junit.extensions.TestSetup$1.protect(TestSetup.java:21)
          at junit.extensions.TestSetup.run(TestSetup.java:25)
          at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
          at junit.extensions.TestSetup$1.protect(TestSetup.java:21)
          at junit.extensions.TestSetup.run(TestSetup.java:25)

          FAILURES!!!
          Tests run: 9164, Failures: 1, Errors: 0

          Show
          Rick Hillegas added a comment - Thanks for the revised patch with test, Siddharth. Looks good to me. Committed at subversion revision 1140222. Regression tests passed cleanly for me except for a ping test problem which does not seem to be related to your patch: 1) testPingWithWrongHost(org.apache.derbyTesting.functionTests.tests.derbynet.NetworkServerControlClientCommandTest)junit.framework.AssertionFailedError: Could not find expectedString:Unable to find host in output:Mon Jun 27 07:21:11 PDT 2011 : Could not connect to Derby Network Server on host nothere, port 1527: Operation timed out at org.apache.derbyTesting.junit.BaseTestCase.assertExecJavaCmdAsExpected(BaseTestCase.java:516) at org.apache.derbyTesting.functionTests.tests.derbynet.NetworkServerControlClientCommandTest.assertFailedPing(NetworkServerControlClientCommandTest.java:147) at org.apache.derbyTesting.functionTests.tests.derbynet.NetworkServerControlClientCommandTest.testPingWithWrongHost(NetworkServerControlClientCommandTest.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at org.apache.derbyTesting.junit.BaseTestCase.runBare(BaseTestCase.java:112) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24) at junit.extensions.TestSetup$1.protect(TestSetup.java:21) at junit.extensions.TestSetup.run(TestSetup.java:25) at org.apache.derbyTesting.junit.BaseTestSetup.run(BaseTestSetup.java:57) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24) at junit.extensions.TestSetup$1.protect(TestSetup.java:21) at junit.extensions.TestSetup.run(TestSetup.java:25) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24) at junit.extensions.TestSetup$1.protect(TestSetup.java:21) at junit.extensions.TestSetup.run(TestSetup.java:25) FAILURES!!! Tests run: 9164, Failures: 1, Errors: 0
          Hide
          Kathey Marsden added a comment -

          This looks like a good candidate for backport.

          Show
          Kathey Marsden added a comment - This looks like a good candidate for backport.
          Hide
          Myrna van Lunteren added a comment -

          reopen for backport to 10.8

          Show
          Myrna van Lunteren added a comment - reopen for backport to 10.8
          Hide
          Myrna van Lunteren added a comment -

          backported to 10.8 with revision 1160950.

          Show
          Myrna van Lunteren added a comment - backported to 10.8 with revision 1160950.
          Hide
          Kathey Marsden added a comment -

          Reopen for 10.5 backport consideration. If working on the backport for this issue. Temporarily assign yourself and add a comment that you are working on it. When finished, reresolve with the new fix versions or label backport_reject_10_x as appropriate.

          Show
          Kathey Marsden added a comment - Reopen for 10.5 backport consideration. If working on the backport for this issue. Temporarily assign yourself and add a comment that you are working on it. When finished, reresolve with the new fix versions or label backport_reject_10_x as appropriate.
          Hide
          Kathey Marsden added a comment -

          Reassigning to myself for backport

          Show
          Kathey Marsden added a comment - Reassigning to myself for backport
          Hide
          Kathey Marsden added a comment -

          10.5 required manual merge. Attaching patch derby-4779_10_5_diff.txt

          Show
          Kathey Marsden added a comment - 10.5 required manual merge. Attaching patch derby-4779_10_5_diff.txt
          Hide
          Kathey Marsden added a comment -

          Resolving and reassigning to Siddharth. Ported back to 10.5 along with DERBY-5304

          Show
          Kathey Marsden added a comment - Resolving and reassigning to Siddharth. Ported back to 10.5 along with DERBY-5304

            People

            • Assignee:
              Siddharth Srivastava
              Reporter:
              Rick Hillegas
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development