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

Misleading stack traces for exceptions raised by the JDBC 4.0 embedded driver

Agile BoardAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments


    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s:
    • Fix Version/s:,
    • Component/s: JDBC
    • Labels:
    • Environment:
      Java SE 6, Derby with JDBC 4.0 compiled in.


      When the embedded driver raises an SQLException, its stack trace always
      says it is created in SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA().
      This is not correct.

      At some point, SQLExceptionFactory40.getSQLException() set the stack trace
      of the SQLException to the stack trace of the non-SQLException that caused
      it, if there were one. This was probably done to mimic the behaviour of
      EmbedSQLException, which overrides printStackTrace() to achieve the
      same. Later, code was added to ferry arguments over DRDA. This code created
      a dummy exception which the old code interpreted as a non-SQLException
      whose stack trace should be used for the main exception. Therefore, all
      exceptions now have the same stack trace as the dummy exception created in

      I think the best solution is not to set the stack trace explicitly, not
      even when the SQLException is caused by a non-SQLException.
      EmbedSQLException overrides printStackTrace() because throwables in Java
      1.3 didn't have initCause()/getCause(), so it was the only way to preserve
      the original stack trace. Since the SQLExceptions in JDBC 4.0 have
      initCause()/getCause(), there is no reason why the JDBC4 driver should
      mimic EmbedSQLException's workaround for not having these methods.


        1. derby-1991.diff
          4 kB
          Knut Anders Hatlen
        2. derby-1991.stat
          0.3 kB
          Knut Anders Hatlen



            • Assignee:
              knutanders Knut Anders Hatlen
              knutanders Knut Anders Hatlen


              • Created:

                Issue deployment