Derby
  1. Derby
  2. DERBY-4672

NullPointerException in insert from nested select with parameter

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 10.0.2.1, 10.1.1.0, 10.2.2.0, 10.4.1.3, 10.5.3.0, 10.6.1.0, 10.7.1.1
    • Fix Version/s: None
    • Component/s: SQL
    • Urgency:
      Normal
    • Issue & fix info:
      Repro attached

      Description

      Compilation of this statement fails with a NullPointerException:

      insert into t select x from (select ? from t) s

      It should fail, but not with a NullPointerException. The expected error is:

      ERROR 42X34: There is a ? parameter in the select list. This is not allowed.

      I found this issue when testing the fix for DERBY-4671. It is not the same issue, since DERBY-4671 was a regression in 10.6.1, and this issue has been there for a long time (I've only tested back to 10.2.2.0, but it may have existed even before that).

      java.lang.NullPointerException
      at org.apache.derby.impl.sql.compile.BaseTypeCompiler.numberStorable(BaseTypeCompiler.java:316)
      at org.apache.derby.impl.sql.compile.NumericTypeCompiler.storable(NumericTypeCompiler.java:329)
      at org.apache.derby.impl.sql.compile.ResultColumn.checkStorableExpression(ResultColumn.java:887)
      at org.apache.derby.impl.sql.compile.ResultColumn.checkStorableExpression(ResultColumn.java:879)
      at org.apache.derby.impl.sql.compile.ResultColumnList.checkStorableExpressions(ResultColumnList.java:953)
      at org.apache.derby.impl.sql.compile.InsertNode.bindStatement(InsertNode.java:456)
      at org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:324)
      at org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:90)
      at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:828)
      at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(EmbedPreparedStatement.java:130)
      at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(EmbedPreparedStatement20.java:82)
      at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(EmbedPreparedStatement30.java:63)
      at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(EmbedPreparedStatement40.java:40)
      at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Driver40.java:105)
      at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(EmbedConnection.java:1607)
      at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(EmbedConnection.java:1435)

      1. repro.sql
        0.1 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Knut Anders Hatlen created issue -
          Knut Anders Hatlen made changes -
          Field Original Value New Value
          Link This issue blocks DERBY-4671 [ DERBY-4671 ]
          Hide
          Knut Anders Hatlen added a comment -

          Attaching repro script for the bug.

          $ java -jar derbyrun.jar ij repro.sql
          ij version 10.7
          ij> connect 'jdbc:derby:db;create=true';
          ij> create table t(x int);
          0 rows inserted/updated/deleted
          ij> prepare ps as 'insert into t select x from (select ? from t) s';
          ERROR XJ001: Java exception: ': java.lang.NullPointerException'.

          Show
          Knut Anders Hatlen added a comment - Attaching repro script for the bug. $ java -jar derbyrun.jar ij repro.sql ij version 10.7 ij> connect 'jdbc:derby:db;create=true'; ij> create table t(x int); 0 rows inserted/updated/deleted ij> prepare ps as 'insert into t select x from (select ? from t) s '; ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
          Knut Anders Hatlen made changes -
          Attachment repro.sql [ 12445170 ]
          Hide
          Knut Anders Hatlen added a comment -

          Verified that the bug is present all the way back to 10.0.2.1.

          Show
          Knut Anders Hatlen added a comment - Verified that the bug is present all the way back to 10.0.2.1.
          Knut Anders Hatlen made changes -
          Affects Version/s 10.1.1.0 [ 10993 ]
          Affects Version/s 10.0.2.1 [ 10991 ]
          Issue & fix info [Repro attached]
          Rick Hillegas made changes -
          Link This issue is blocked by DERBY-4683 [ DERBY-4683 ]
          Rick Hillegas made changes -
          Link This issue is blocked by DERBY-4683 [ DERBY-4683 ]
          Rick Hillegas made changes -
          Link This issue is related to DERBY-4683 [ DERBY-4683 ]
          Knut Anders Hatlen made changes -
          Link This issue relates to DERBY-4671 [ DERBY-4671 ]
          Knut Anders Hatlen made changes -
          Link This issue blocks DERBY-4671 [ DERBY-4671 ]
          Knut Anders Hatlen made changes -
          Link This issue is related to DERBY-4683 [ DERBY-4683 ]
          Rick Hillegas made changes -
          Affects Version/s 10.7.1.1 [ 12315564 ]
          Affects Version/s 10.7.1.0 [ 12314971 ]
          Hide
          Cedric Dandoy added a comment -

          The test case can be simplified to
          insert into t select ? from t

          For example:
          connection.prepareStatement("insert into a select ? from a");

          The execution fails with the following exception:
          java.sql.SQLException: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ001, SQLERRMC: java.lang.NullPointerExceptionXJ001.U
          at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
          at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
          at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
          ...
          Caused by: org.apache.derby.client.am.SqlException: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ001, SQLERRMC: java.lang.NullPointerExceptionXJ001.U
          at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
          at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
          at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
          at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
          at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
          at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
          at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
          at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
          at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
          at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
          at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
          ... 23 more

          Using 10.6.1.0.

          Show
          Cedric Dandoy added a comment - The test case can be simplified to insert into t select ? from t For example: connection.prepareStatement("insert into a select ? from a"); The execution fails with the following exception: java.sql.SQLException: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ001, SQLERRMC: java.lang.NullPointerExceptionXJ001.U at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source) at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source) ... Caused by: org.apache.derby.client.am.SqlException: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ001, SQLERRMC: java.lang.NullPointerExceptionXJ001.U at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source) at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source) at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source) at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source) at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source) at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source) at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source) at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source) ... 23 more Using 10.6.1.0.
          Hide
          Knut Anders Hatlen added a comment -

          The NPE in "insert into t select ? from t" was fixed in 10.6.2.1. See DERBY-4671.

          Show
          Knut Anders Hatlen added a comment - The NPE in "insert into t select ? from t" was fixed in 10.6.2.1. See DERBY-4671 .
          Dag H. Wanvik made changes -
          Labels derby_triage10_8
          Urgency Normal
          Gavin made changes -
          Workflow jira [ 12511489 ] Default workflow, editable Closed status [ 12800249 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Development