db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r543428 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/
Date Fri, 01 Jun 2007 08:38:18 GMT
Author: kahatlen
Date: Fri Jun  1 01:38:16 2007
New Revision: 543428

URL: http://svn.apache.org/viewvc?view=rev&rev=543428
Log:
DERBY-2692: Client driver doesn't chain exceptions received from the server

Always use initCause() to chain exceptions, also when they are chained
with setNextException().

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Diagnosable.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ExceptionFormatter.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/XaException.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Diagnosable.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Diagnosable.java?view=diff&rev=543428&r1=543427&r2=543428
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Diagnosable.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Diagnosable.java Fri Jun  1
01:38:16 2007
@@ -24,7 +24,5 @@
 public interface Diagnosable {
     public Sqlca getSqlca();
 
-    public java.lang.Throwable getThrowable();
-
     public void printTrace(java.io.PrintWriter printWriter, String messageHeader);
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ExceptionFormatter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ExceptionFormatter.java?view=diff&rev=543428&r1=543427&r2=543428
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ExceptionFormatter.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ExceptionFormatter.java Fri
Jun  1 01:38:16 2007
@@ -36,11 +36,7 @@
                 header = messageHeader + "[" + "SQLException@" + Integer.toHexString(e.hashCode())
+ "]";
                 printWriter.println(header + " java.sql.SQLException");
 
-                java.lang.Throwable throwable = null;
-                try {
-                    throwable = ((Diagnosable) e).getThrowable();
-                } catch (java.lang.NoSuchMethodError doNothing) {
-                }
+                java.lang.Throwable throwable = e.getCause();
                 if (throwable != null) {
                     printTrace(throwable, printWriter, header);
                 }
@@ -185,27 +181,6 @@
             printWriter.println(header + " Stack trace follows");
 
             e.printStackTrace(printWriter);
-
-            if (!((org.apache.derby.client.am.Configuration.jreLevelMajor == 1) &&
-                    (org.apache.derby.client.am.Configuration.jreLevelMinor >= 4)) ||
-                    (org.apache.derby.client.am.Configuration.jreLevelMajor > 1)) { //
If not jre 1.4 or above, we need to print the cause if there is one
-                // For jre 1.4 or above, e.printStackTrace() will print the cause automatically
-                if (e instanceof Diagnosable) {
-                    java.lang.Throwable throwable = null;
-                    try {
-                        throwable = ((Diagnosable) e).getThrowable();
-                    } catch (java.lang.NoSuchMethodError doNothing) {
-                    }
-                    if (throwable != null) {
-                        printWriter.print("Caused by: ");
-                        if (throwable instanceof java.sql.SQLException) {
-                            throwable.printStackTrace(printWriter);
-                        } else {
-                            printTrace(throwable, printWriter, header);
-                        }
-                    }
-                }
-            }
         }
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?view=diff&rev=543428&r1=543427&r2=543428
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Fri Jun 
1 01:38:16 2007
@@ -24,7 +24,6 @@
 import java.sql.SQLException;
 import java.util.TreeMap;
 
-import org.apache.derby.iapi.services.info.JVMInfo;
 import org.apache.derby.shared.common.i18n.MessageUtil;
 import org.apache.derby.shared.common.error.ExceptionUtil;
 import org.apache.derby.shared.common.reference.SQLState;
@@ -315,15 +314,13 @@
     }
     
     /**
-     * Set the cause of this exception based on its type and
-     * the current runtime version of Java
+     * Set the cause of this exception based on its type.
+     * <code>SQLException</code>s and <code>SqlException</code>s
are
+     * linked with <code>setNextException()</code> and <code>initCause()</code>.
+     * All other exception types are linked with <code>initCause()</code>.
      */
-    protected void setThrowable(Throwable throwable)
+    private void setThrowable(Throwable throwable)
     {
-        throwable_ = throwable;
-        
-        // If the throwable is a SQL exception, use nextException rather
-        // than chained exceptions
         if ( throwable instanceof SqlException )
         {
             setNextException((SqlException) throwable);
@@ -332,23 +329,10 @@
         {
             setNextException((SQLException) throwable );
         }
-        else if ( throwable != null )
-        {
-            // Set up a string indicating the cause if the current runtime
-            // doesn't support the initCause() method.  This is then used
-            // by getMessage() when it composes the message string.
-            if (JVMInfo.JDK_ID < JVMInfo.J2SE_14 )
-            {
-                causeString_ = " " + 
-                    getMessageUtil().getTextMessage(CAUSED_BY_EXCEPTION_ID)  + " " +
-                    throwable.getClass() + ": " + throwable.getMessage();
-            }
-            else
-            {
-                initCause(throwable);
-            }
-        }
 
+        if (throwable != null) {
+            initCause(throwable);
+        }
     }
         
     /**
@@ -377,14 +361,7 @@
         // where we decide which exception to create
         SQLException sqle = exceptionFactory.getSQLException(getMessage(), getSQLState(),

             getErrorCode());
-
-        // If we're in a runtime that supports chained exceptions, set the cause 
-        // of the SQLException to be this SqlException.  Otherwise the stack
-        // trace is lost.
-         if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
-        {
-            sqle.initCause(this);
-        }
+        sqle.initCause(this);
 
         // Set up the nextException chain
         if ( nextException_ != null )
@@ -408,10 +385,6 @@
 
     public Sqlca getSqlca() {
         return sqlca_;
-    }
-
-    public java.lang.Throwable getThrowable() {
-        return throwable_;
     }
 
     public String getMessage() {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java?view=diff&rev=543428&r1=543427&r2=543428
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlWarning.java Fri Jun  1
01:38:16 2007
@@ -22,7 +22,6 @@
 package org.apache.derby.client.am;
 
 import java.sql.SQLWarning;
-import org.apache.derby.iapi.services.info.JVMInfo;
 
 /**
  * This represents a warning versus a full exception.  As with
@@ -96,12 +95,7 @@
         SQLWarning sqlw = new SQLWarning(getMessage(), getSQLState(), 
             getErrorCode());
 
-        // If we're in a runtime that supports chained exceptions, set the cause 
-        // of the SQLWarning to be this SqlWarning.
-         if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
-        {
-            sqlw.initCause(this);
-        }
+        sqlw.initCause(this);
 
         // Set up the nextException chain
         if ( nextWarning_ != null )

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/XaException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/XaException.java?view=diff&rev=543428&r1=543427&r2=543428
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/XaException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/XaException.java Fri Jun  1
01:38:16 2007
@@ -23,7 +23,6 @@
 
 
 public class XaException extends javax.transaction.xa.XAException implements Diagnosable
{
-    java.lang.Throwable throwable_ = null;
 
     //-----------------constructors-----------------------------------------------
 
@@ -36,12 +35,7 @@
 
     public XaException(LogWriter logWriter, java.lang.Throwable throwable) {
         super();
-        throwable_ = throwable;
-        if (((org.apache.derby.client.am.Configuration.jreLevelMajor == 1) &&
-                (org.apache.derby.client.am.Configuration.jreLevelMinor >= 4)) ||
-                (org.apache.derby.client.am.Configuration.jreLevelMajor > 1)) { // jre
1.4 or above, init the cause
-            initCause(throwable);
-        }
+        initCause(throwable);
         if (logWriter != null) {
             logWriter.traceDiagnosable(this);
         }
@@ -58,12 +52,7 @@
     public XaException(LogWriter logWriter, java.lang.Throwable throwable, int errcode) {
         super();
         errorCode = errcode;
-        throwable_ = throwable;
-        if (((org.apache.derby.client.am.Configuration.jreLevelMajor == 1) &&
-                (org.apache.derby.client.am.Configuration.jreLevelMinor >= 4)) ||
-                (org.apache.derby.client.am.Configuration.jreLevelMajor > 1)) { // jre
1.4 or above, init the cause
-            initCause(throwable);
-        }
+        initCause(throwable);
         if (logWriter != null) {
             logWriter.traceDiagnosable(this);
         }
@@ -78,12 +67,7 @@
 
     public XaException(LogWriter logWriter, java.lang.Throwable throwable, String s) {
         super(s);
-        throwable_ = throwable;
-        if (((org.apache.derby.client.am.Configuration.jreLevelMajor == 1) &&
-                (org.apache.derby.client.am.Configuration.jreLevelMinor >= 4)) ||
-                (org.apache.derby.client.am.Configuration.jreLevelMajor > 1)) { // jre
1.4 or above, init the cause
-            initCause(throwable);
-        }
+        initCause(throwable);
         if (logWriter != null) {
             logWriter.traceDiagnosable(this);
         }
@@ -93,10 +77,6 @@
         return null;
     }
 
-    public java.lang.Throwable getThrowable() {
-        return throwable_;
-    }
-
     public void printTrace(java.io.PrintWriter printWriter, String header) {
         ExceptionFormatter.printTrace(this, printWriter, header);
     }
@@ -105,7 +85,7 @@
     // Because the "next" is a private field in java.sql.SQLException,
     // we have to create a new XaException in order to break the chain with "next" as null.
     XaException copyAsUnchainedXAException(LogWriter logWriter) {
-        XaException xae = new XaException(logWriter, this.getThrowable(), getMessage());
// client error
+        XaException xae = new XaException(logWriter, getCause(), getMessage());
         xae.errorCode = this.errorCode;
         return xae;
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java?view=diff&rev=543428&r1=543427&r2=543428
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java
Fri Jun  1 01:38:16 2007
@@ -73,7 +73,7 @@
     
     /**
      * Make sure a SQLException is chained as a nextSQLException()
-     * rather than as a chained exception
+     * and as a chained exception.
      */
     public void testNextException() {
         SQLException nexte = new SQLException("test");
@@ -83,7 +83,7 @@
         SQLException javae = sqle.getSQLException();
         
         assertEquals(sqle, javae.getCause());
-        assertNull(javae.getCause().getCause());
+        assertEquals(nexte, javae.getCause().getCause());
         assertEquals(nexte, javae.getNextException());
         
         // Make sure exception chaining works with Derby's SqlException
@@ -98,6 +98,7 @@
         
         assertNotNull(javae.getNextException());
         assertEquals(javae.getNextException().getSQLState(), "08000");
+        assertEquals(internalException, javae.getCause().getCause());
     }
 
     /**



Mime
View raw message