Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4356658

questionable printing in SQLException constructors

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 1.4.0
    • 1.2.0
    • core-libs
    • beta
    • generic
    • generic



      Name: cl74495 Date: 07/26/2000


      The constructors for java.sql.SQLException do some questionable printing
      of the stack trace and other info. Granted, this is a minor issue, but
      here are the concerns:

      1. In all four constructors, calls are made to
      java.sql.DriverManager.getLogStream(), which is deprecated.
      A non-deprecated API (DriverManager.getLogWriter() and
      exception.printStackTrace(PrintWriter s)) is available. Why is the
      deprecated API being used?

      2. If the returned logStream is not null, DriverManager.getLogStream()
      is again used to print a stack trace, which doesn't seem like something
      the constructor should automatically do. The catcher of the exception
      should print the stack trace if desired. What is the reason for doing
      this automatically in the constructor, and only when logStream is set?

      3. In two of the constructors, some SQLException info is also printed
      via DriverManager.println. DriverManager.println uses logWriter, but
      the info is printed only if logStream is not null. Again, the catcher
      should get this additional info only if desired, using the public get
      methods available. What is the reason for printing this automatically
      in the constructor, and only when logStream is set?

      Here is the relevant code, from java.sql.SQLException.

          public SQLException(String reason, String SQLState, int vendorCode) {
              ...
      if (!(this instanceof SQLWarning)) {
      if (DriverManager.getLogStream() != null) {
      DriverManager.println("SQLException: SQLState(" + SQLState +
      ") vendor code(" + vendorCode + ")");
      printStackTrace(DriverManager.getLogStream());
      }
      }
          }

          public SQLException(String reason, String SQLState) {
      ...
      if (!(this instanceof SQLWarning)) {
      if (DriverManager.getLogStream() != null) {
      printStackTrace(DriverManager.getLogStream());
      DriverManager.println("SQLException: SQLState(" + SQLState + ")");
      }
      }
          }

          public SQLException(String reason) {
      ...
      if (!(this instanceof SQLWarning)) {
      if (DriverManager.getLogStream() != null) {
      printStackTrace(DriverManager.getLogStream());
      }
      }
          }

          public SQLException() {
      ...
      if (!(this instanceof SQLWarning)) {
      if (DriverManager.getLogStream() != null) {
      printStackTrace(DriverManager.getLogStream());
      }
      }
          }
      (Review ID: 107378)
      ======================================================================

            jellissunw Jon Ellis (Inactive)
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: