Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-6693

Assert failure/ArrayIndexOutOfBoundsException when using COUNT in MERGE matching clause

    XMLWordPrintableJSON

Details

    • Repro attached

    Description

      This (meaningless) statement gives NPE in insane builds and
      assert failure in sane builds:

      s.execute("create table t2(x int)");
      s.execute("create table t1(x int)");
      s.execute("insert into t2 values 3,4");
      s.executeUpdate("merge into t1 using t2 on (t1.x=t2.x) " + 
         "when not matched then insert values (count(*))");
      

      I see it also applies to other aggregates, e.g. MAX.
      stack trace (insane):

      Exception in thread "main" java.sql.SQLException: Java exception: '-1: java.lang.ArrayIndexOutOfBoundsException'.
              at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
              at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
              at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
              at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
              at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
              at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
              at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
              at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
              at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
              at org.apache.derby.impl.jdbc.EmbedStatement.executeLargeUpdate(Unknown Source)
              at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source)
              at derby6565.Derby6565.main(Derby6565.java:46)
      Caused by: ERROR XJ001: Java exception: '-1: java.lang.ArrayIndexOutOfBoundsException'.
              at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
              at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)
              ... 12 more
      Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
              at org.apache.derby.impl.services.bytecode.BCMethod.popStack(Unknown Source)
              at org.apache.derby.impl.services.bytecode.BCMethod.callMethod(Unknown Source)
              at org.apache.derby.impl.sql.compile.ResultColumnList.generateEvaluatedRow(Unknown Source)
              at org.apache.derby.impl.sql.compile.MatchingClauseNode.generateInsertUpdateRow(Unknown Source)
              at org.apache.derby.impl.sql.compile.MatchingClauseNode.generate(Unknown Source)
              at org.apache.derby.impl.sql.compile.MergeNode.generate(Unknown Source)
              at org.apache.derby.impl.sql.compile.StatementNode.generate(Unknown Source)
              at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
              at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
              at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
              ... 4 more
      

      Attachments

        1. derby-6693.status
          1.0 kB
          Dag H. Wanvik
        2. derby-6693.diff
          5 kB
          Dag H. Wanvik

        Activity

          People

            dagw Dag H. Wanvik
            dagw Dag H. Wanvik
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: