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

SQLException(java.lang.Throwable cause) didn't retrun a null in reason field.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 6
    • 6
    • core-libs
    • b59
    • generic
    • generic
    • Verified

      JDK : 6.0-b47
      Platform[s] : Sol 10 sparc
      switch/Mode : default
      DB : ORCL
      Failing Test : java_sql_exceptions/exception/exception_002

      Description:
      ===========
      From the doc, the reason field is defaults to null with SQLException(java.lang.Throwable cause) constructs. However, I am getting output of reason is same as the getCause(). Unless I didn't use the correct method to print out the reason field. I am using getMessage() to print out the reason field.

      java doc
      =========
      public SQLException(java.lang.Throwable cause)
          Constructs a SQLException object with underlying cause; the reason field defaults to null, the SQLState field defaults to null, and the vendorCode field defaults to 0.

      How to reproduce:
      ====================
      javac myexpection.java
      java myexpection

      Test output:
      =============
      SQLException(throw1) called
      Throwable cause is java.lang.Throwable: Cause 1
      Throwable reasons is java.lang.Throwable: Cause 1
      Throwable sqlState is null
      Throwable vendor code is 0


      Specific Machine Info:
      =====================
      SunOS orthello 5.10 Generic sun4u sparc SUNW,Ultra-60


      myexpection.java
      =================

      import java.lang.Exception.*;
      import java.sql.*;

      import java.io.*;

      public class myexpection {
          public static void main (String args[]) {
             
               Throwable throw0 = null;
               Throwable throw1 = new Throwable("Cause 1");
               String reasons = "reasons for SQLEx";
               String sqlState = "sqlState for SQLEx";
               int myVendorCode = 99999;
               try {
                   throw new SQLException(throw1);
               }catch (SQLException sqlEx){
                   System.out.println("SQLException(throw1) called");
                   System.out.println("Throwable cause is " + sqlEx.getCause());
                   System.out.println("Throwable reasons is " + sqlEx.getMessage());
                   System.out.println("Throwable sqlState is " + sqlEx.getSQLState());
                   System.out.println("Throwable vendor code is " + sqlEx.getErrorCode());
                   
               }
             
          }
          
      }
      BatchUpdateException(java.lang.Throwable cause) constructs too.

            ahandasunw Amit Handa (Inactive)
            tacheung Tak Wing Cheung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: