Derby
  1. Derby
  2. DERBY-4449

ArrayIndexOutOfBoundsException when inserting DEFAULT into unspecified column

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.5.3.0, 10.6.1.0
    • Fix Version/s: 10.5.3.1, 10.7.1.1
    • Component/s: SQL
    • Labels:
      None

      Description

      When inserting rows into a table, with just a subset of the table's columns in the target column list, an ArrayIndexOutOfBoundsException is raised if the table constructor contains the same number of columns as the target table, and the extra columns are specified as DEFAULT:

      ij> create table t (a int, b int);
      0 rows inserted/updated/deleted
      ij> insert into t(a) values (1,default);
      ERROR XJ001: Java exception: '1 >= 1: java.lang.ArrayIndexOutOfBoundsException'.

      The insert statement should have failed with this error:

      ERROR 42802: The number of values assigned is not the same as the number of specified or implied columns.

      1. derby-4449-10.5.diff
        2 kB
        Lily Wei
      2. derby-4449-10.6.diff
        2 kB
        Lily Wei
      3. derby-4449-1a.diff
        2 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Hide
          Knut Anders Hatlen added a comment -

          Thanks Lily. Committed revision 963617.

          Show
          Knut Anders Hatlen added a comment - Thanks Lily. Committed revision 963617.
          Hide
          Lily Wei added a comment -

          Attach back port to 10.6 (derby-4449-10.6.diff) suites.All and derbyall test suites are all fine. It is ready to submit to 10.6 port.

          Show
          Lily Wei added a comment - Attach back port to 10.6 (derby-4449-10.6.diff) suites.All and derbyall test suites are all fine. It is ready to submit to 10.6 port.
          Hide
          Lily Wei added a comment -

          Will back port to 10.6

          Show
          Lily Wei added a comment - Will back port to 10.6
          Hide
          Knut Anders Hatlen added a comment -

          Restoring fix version 10.7.0.0.
          (This bug is now in the somewhat unusual state of being fixed in 10.7 and 10.5, but not in 10.6.)

          Show
          Knut Anders Hatlen added a comment - Restoring fix version 10.7.0.0. (This bug is now in the somewhat unusual state of being fixed in 10.7 and 10.5, but not in 10.6.)
          Hide
          Lily Wei added a comment -

          finish backport to 10.5

          Show
          Lily Wei added a comment - finish backport to 10.5
          Hide
          Lily Wei added a comment -

          derby-4449-10.5.diff passed suites.all and derbyall. It is ready to submit.

          Show
          Lily Wei added a comment - derby-4449-10.5.diff passed suites.all and derbyall. It is ready to submit.
          Hide
          Lily Wei added a comment -

          derby-4449-10.5.diff is the patch for back port to 10.5

          Show
          Lily Wei added a comment - derby-4449-10.5.diff is the patch for back port to 10.5
          Hide
          Lily Wei added a comment -

          Will back port to 10.5

          Show
          Lily Wei added a comment - Will back port to 10.5
          Hide
          Knut Anders Hatlen added a comment -

          Thanks, Bryan!
          Committed revision 951366.

          Show
          Knut Anders Hatlen added a comment - Thanks, Bryan! Committed revision 951366.
          Hide
          Bryan Pendleton added a comment -

          +1 to your proposed fix.

          Show
          Bryan Pendleton added a comment - +1 to your proposed fix.
          Hide
          Knut Anders Hatlen added a comment -

          Regression tests ran cleanly.

          Show
          Knut Anders Hatlen added a comment - Regression tests ran cleanly.
          Hide
          Knut Anders Hatlen added a comment -

          The attached patch adds a check of the array index and skips the look-up in the array if the index is out of range, so that the null check right below is triggered instead and makes the statement fail gracefully. It also adds a regression test case in InsertTest.

          I've started the full regression test suite.

          Show
          Knut Anders Hatlen added a comment - The attached patch adds a check of the array index and skips the look-up in the array if the index is out of range, so that the null check right below is triggered instead and makes the statement fail gracefully. It also adds a regression test case in InsertTest. I've started the full regression test suite.
          Hide
          Knut Anders Hatlen added a comment -

          Here's the failing code:

          // Get ColumnDescriptor by name or by position?
          ColumnDescriptor cd;
          if (tcl == null)

          { cd = ttd.getColumnDescriptor(index + 1); }

          else

          { ResultColumn trc = (ResultColumn) tcl.elementAt(index); cd = ttd.getColumnDescriptor(trc.getName()); }

          // Too many RCs if no ColumnDescriptor
          if (cd == null)

          { throw StandardException.newException(SQLState.LANG_TOO_MANY_RESULT_COLUMNS, ttd.getQualifiedName()); }

          The call to tcl.elementAt(index) is the one that raises the AIOOBE. Note that the code expects that there may be too many columns, and then getColumnDescriptor() should return null. But in the case where we have a target column list, we fail before we get to the point where getColumnDescriptor() is called.

          I think it would be sufficient to check that the index is within range before calling elementAt() and set cd to null if it's not.

          Show
          Knut Anders Hatlen added a comment - Here's the failing code: // Get ColumnDescriptor by name or by position? ColumnDescriptor cd; if (tcl == null) { cd = ttd.getColumnDescriptor(index + 1); } else { ResultColumn trc = (ResultColumn) tcl.elementAt(index); cd = ttd.getColumnDescriptor(trc.getName()); } // Too many RCs if no ColumnDescriptor if (cd == null) { throw StandardException.newException(SQLState.LANG_TOO_MANY_RESULT_COLUMNS, ttd.getQualifiedName()); } The call to tcl.elementAt(index) is the one that raises the AIOOBE. Note that the code expects that there may be too many columns, and then getColumnDescriptor() should return null. But in the case where we have a target column list, we fail before we get to the point where getColumnDescriptor() is called. I think it would be sufficient to check that the index is within range before calling elementAt() and set cd to null if it's not.
          Hide
          Knut Anders Hatlen added a comment -

          42X06 may be a better error than 42802, based on this script:

          ij> create table t(x int);
          0 rows inserted/updated/deleted
          ij> insert into t values (default, default);
          ERROR 42X06: Too many result columns specified for table '"APP"."T"'.
          ij> insert into t values (default, default);
          ERROR XJ001: Java exception: '1 >= 1: java.lang.ArrayIndexOutOfBoundsException'.

          Show
          Knut Anders Hatlen added a comment - 42X06 may be a better error than 42802, based on this script: ij> create table t(x int); 0 rows inserted/updated/deleted ij> insert into t values (default, default); ERROR 42X06: Too many result columns specified for table '"APP"."T"'. ij> insert into t values (default, default); ERROR XJ001: Java exception: '1 >= 1: java.lang.ArrayIndexOutOfBoundsException'.

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development