Derby
  1. Derby
  2. DERBY-1629

Exceptions thrown by code in procedures or triggers are not handled/thrown correctly by Derby

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: 10.3.1.4
    • Component/s: JDBC, SQL
    • Labels:
      None
    • Urgency:
      Normal
    • Issue & fix info:
      Release Note Needed
    • Bug behavior facts:
      Regression

      Description

      In Java SE 6 runtime environments, an application may not get the SQL Exception with SQL State 38000 when execution of a trigger or procedure fails with an exception caused by Derby internals. Instead, they will get the underlying exception with it's SQL State. For an example of this, see lang/procedureInTrigger.sql, which has different output for Java SE 6 (encoded in the master/jdk16/procedureInTrigger.out file) than for other Java SE runtimes.

      1. DERBY-1629_j9canon.diff
        0.9 kB
        Myrna van Lunteren

        Issue Links

          Activity

          David Van Couvering created issue -
          Andrew McIntyre made changes -
          Field Original Value New Value
          Summary StandardExceptoin.unexpectedUserException() does not correctly catch internally generated exceptions as of JDK 1.6 StandardException.unexpectedUserException() does not correctly catch internally generated exceptions as of JDK 1.6
          Rick Hillegas made changes -
          Fix Version/s 10.2.0.0 [ 11187 ]
          Urgency Normal
          David Van Couvering made changes -
          Priority Major [ 3 ] Minor [ 4 ]
          David Van Couvering made changes -
          Description In non-JDK 1.6 builds, the exceptions Derby throws are all of class EmbedSQLException. As of JDK 1.6, that is no longer true. Instead we throw a "native" SQL Exception.

          That makes the following code incorrect:

          public static StandardException unexpectedUserException(Throwable t)
          {
          /*
          ** If we have a SQLException that isn't a Util
          ** (i.e. it didn't come from cloudscape), then we check
          ** to see if it is a valid user defined exception range
          ** (38001-38XXX). If so, then we convert it into a
          ** StandardException without further ado.
          */
          if ((t instanceof SQLException) &&
          !(t instanceof EmbedSQLException))
          {
          SQLException sqlex = (SQLException)t;
          String state = sqlex.getSQLState();
          if ((state != null) &&
          (state.length() == 5) &&
          state.startsWith("38") &&
          !state.equals("38000"))
          {
          StandardException se = new StandardException(state, sqlex.getMessage());
          if (sqlex.getNextException() != null)
          {
          se.setNestedException(sqlex.getNextException());
          }
          return se;
          }
          }

          I am not sure how we can detect internally-thrown SQL Exceptions and distinguish them from user exceptions, but this does need to be looked at.

          Right now procedureInTrigger.sql is failing for JDK 1.6 due to this error. I may check in a jdk16-specific version of this file so at least derbyall can pass.
          In Java SE 6 runtime environments, an application may not get the SQL Exception with SQL State 38000 when execution of a trigger or procedure fails with an exception caused by Derby internals. Instead, they will get the underlying exception with it's SQL State. For an example of this, see lang/procedureInTrigger.sql, which has different output for Java SE 6 (encoded in the master/jdk16/procedureInTrigger.out file) than for other Java SE runtimes.
          Derby Info [Existing Application Impact, Regression]
          Myrna van Lunteren made changes -
          Attachment DERBY-1629_j9canon.diff [ 12338106 ]
          Myrna van Lunteren made changes -
          Derby Info [Existing Application Impact, Regression] [Patch Available, Existing Application Impact, Regression]
          David Van Couvering made changes -
          Derby Info [Regression, Existing Application Impact, Patch Available] [Existing Application Impact, Regression]
          David Van Couvering made changes -
          Summary StandardException.unexpectedUserException() does not correctly catch internally generated exceptions as of JDK 1.6 Exceptions thrown by code in procedures or triggers are not handled/thrown correctly by Derby
          Andrew McIntyre made changes -
          Component/s SQL [ 11408 ]
          Component/s JDBC [ 11407 ]
          Mike Matrigali made changes -
          Link This issue relates to DERBY-1729 [ DERBY-1729 ]
          Rick Hillegas made changes -
          Fix Version/s 10.2.2.0 [ 12312027 ]
          Fix Version/s 10.2.1.0 [ 11187 ]
          Rick Hillegas made changes -
          Fix Version/s 10.2.3.0 [ 12312215 ]
          Fix Version/s 10.2.2.0 [ 12312027 ]
          Andrew McIntyre made changes -
          Fix Version/s 10.2.3.0 [ 12312215 ]
          Knut Anders Hatlen made changes -
          Link This issue relates to DERBY-2545 [ DERBY-2545 ]
          Øystein Grøvlen made changes -
          Resolution Duplicate [ 3 ]
          Fix Version/s 10.3.0.0 [ 12310800 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Dag H. Wanvik made changes -
          Bug behavior facts [Regression]
          Dag H. Wanvik made changes -
          Issue & fix info [Existing Application Impact] [Release Note Needed]
          Kathey Marsden made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Gavin made changes -
          Workflow jira [ 12377268 ] Default workflow, editable Closed status [ 12799811 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              David Van Couvering
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development