db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r537412 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/error/ engine/org/apache/derby/iapi/services/context/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/impl/load/ engine/org/apache/derby/impl/services/monitor/ ...
Date Sat, 12 May 2007 13:14:26 GMT
Author: kahatlen
Date: Sat May 12 06:14:25 2007
New Revision: 537412

URL: http://svn.apache.org/viewvc?view=rev&rev=537412
Log:
DERBY-2472 (partial) Use Throwable.initCause() to improve error reporting

Replace StandardException's implementation of exception chaining with
initCause/getCause.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ErrorStringBuilder.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_Generic.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java Sat
May 12 06:14:25 2007
@@ -57,7 +57,6 @@
 	/*
 	 * Exception State
 	 */
-	private Throwable nestedException;
 	private transient Object[] arguments;
 	private int severity;
 	private String textMessage;
@@ -85,8 +84,10 @@
 
 		this.severity = getSeverityFromIdentifier(messageID);
 		this.sqlState = getSQLStateFromIdentifier(messageID);
-		this.nestedException = t;
 		this.arguments = args;
+		if (t != null) {
+			initCause(t);
+		}
 
 		if (SanityManager.DEBUG)
 		{
@@ -129,23 +130,6 @@
 	}
 
 	/**
-	 * Sets the nested exception for this exception.
-	 */
-	public final void setNestedException(Throwable nestedException)
-	{
-		this.nestedException = nestedException;
-	}
-
-	/**
-	 * Returns the nested exception for this exception,
-	 * if there is one.
-	 */
-	public final Throwable getNestedException()
-	{
-		return nestedException;
-	}
-
-	/**
 		Yes, report me. Errors that need this method to return
 		false are in the minority.
 	*/
@@ -446,7 +430,7 @@
     {
         StandardException se = new StandardException( MessageID, localizedMessage);
         if( t != null)
-            se.nestedException = t;
+            se.initCause(t);
         return se;
     }
 
@@ -472,7 +456,7 @@
 				StandardException se = new StandardException(state, sqlex.getMessage());
 				if (sqlex.getNextException() != null)		
 				{	
-					se.setNestedException(sqlex.getNextException());
+					se.initCause(sqlex.getNextException());
 				}
 				return se;
 			}
@@ -583,7 +567,7 @@
 				StandardException se = new StandardException(sqlState, "(" + sqle.getErrorCode()  + ")
" + sqle.getMessage());
 				sqle = sqle.getNextException();
 				if (sqle != null)
-					se.setNestedException(plainWrapException(sqle));
+					se.initCause(plainWrapException(sqle));
 				return se;
 			}
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ErrorStringBuilder.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ErrorStringBuilder.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ErrorStringBuilder.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/context/ErrorStringBuilder.java
Sat May 12 06:14:25 2007
@@ -21,7 +21,6 @@
 
 package org.apache.derby.iapi.services.context;
 
-import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.stream.PrintWriterGetHeader;
 
 import java.io.StringWriter;
@@ -91,20 +90,11 @@
 
 			t.printStackTrace(printWriter);
 
-
-			if (t instanceof StandardException) {
-				t = ((StandardException)t).getNestedException();
-			}
-			else if (t instanceof ExceptionInInitializerError) {
-				t = ((ExceptionInInitializerError) t).getException();
-			}
-			else if (t instanceof java.lang.reflect.InvocationTargetException) {
-				t = ((java.lang.reflect.InvocationTargetException) t).getTargetException();
-			}
-			else if (t instanceof java.sql.SQLException) {
-				t = ((java.sql.SQLException)t).getNextException();
+			if (t instanceof java.sql.SQLException) {
+				Throwable next = ((java.sql.SQLException)t).getNextException();
+				t = (next == null) ? t.getCause() : next;
 			} else {
-				t = null;
+				t = t.getCause();
 			}
 
 			if (level > 0)	

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Sat May
12 06:14:25 2007
@@ -1812,7 +1812,7 @@
 		} catch (StandardException mse) {
 			SQLException se = newSQLException(SQLState.BOOT_DATABASE_FAILED, dbname);
 
-			Throwable ne = mse.getNestedException();
+			Throwable ne = mse.getCause();
 			SQLException nse;
 
 			/*

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
Sat May 12 06:14:25 2007
@@ -379,7 +379,7 @@
 
 			nextSQLException = Util.generateCsSQLException(se);
 
-			wrapInSQLException(nextSQLException, se.getNestedException());
+			wrapInSQLException(nextSQLException, se.getCause());
 
 		} else {
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/Import.java Sat May 12 06:14:25
2007
@@ -330,7 +330,7 @@
         
         StandardException se = StandardException.newException
             ( SQLState.UNEXPECTED_IMPORT_ERROR, new Integer( lineNumber ), inputFile, t.getMessage()
);
-        se.setNestedException( t );
+        se.initCause(t);
 
         return PublicAPI.wrapStandardException(se);
     }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
Sat May 12 06:14:25 2007
@@ -1840,14 +1840,15 @@
             
 		} catch (Throwable t) {
 
+			StandardException se;
 			// ensure that the severity will shutdown the service
 			if ((t instanceof StandardException) && (((StandardException) t).getSeverity()
== ExceptionSeverity.DATABASE_SEVERITY))
-				;
+				se = (StandardException) t;
 			else
-				t = Monitor.exceptionStartingModule(t);
+				se = Monitor.exceptionStartingModule(t);
 
 			if (cm != previousCM) {
-				cm.cleanupOnError(t);
+				cm.cleanupOnError(se);
 			}
 
 			if (ts != null) {
@@ -1865,16 +1866,13 @@
 			}
 
 
-			Throwable nested = ((StandardException) t).getNestedException();
+			Throwable nested = se.getCause();
 
 			// never hide ThreadDeath
 			if (nested instanceof ThreadDeath)
-				throw (ThreadDeath) t;
+				throw (ThreadDeath) nested;
 
-			if (nested instanceof StandardException)
-				throw (StandardException) t;
-
-			throw (StandardException) t;
+			throw se;
 
 		} finally {
 			if ((previousCM == cm) && (sb != null))

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
Sat May 12 06:14:25 2007
@@ -613,7 +613,7 @@
 				dm.invalidateFor(td, DependencyManager.DROP_TABLE, this);
 				tran.dropConglomerate(td.getHeapConglomerateId());
 			} catch (StandardException e) {
-				e.setNestedException(topLevelStandardException);
+				e.initCause(topLevelStandardException);
 				topLevelStandardException = e;
 			}
 		}
@@ -622,7 +622,7 @@
 		try {
 			internalCommit(true);
 		} catch (StandardException e) {
-			e.setNestedException(topLevelStandardException);
+			e.initCause(topLevelStandardException);
 			topLevelStandardException = e;
 		}
 		if (topLevelStandardException != null) throw topLevelStandardException;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
Sat May 12 06:14:25 2007
@@ -383,7 +383,7 @@
 				} catch (StandardException sqle) {
 
 					if (noInvalidate != null)
-						sqle.setNestedException(noInvalidate);
+						sqle.initCause(noInvalidate);
 
 					noInvalidate = sqle;
 				}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_Generic.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_Generic.java?view=diff&rev=537412&r1=537411&r2=537412
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_Generic.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_Generic.java
Sat May 12 06:14:25 2007
@@ -120,16 +120,8 @@
 		
 		catch (Throwable t)
 		{
-			
-			while (t != null) {
-				FAIL(t.toString());
-				t.printStackTrace(out.getPrintWriter());
-				if (t instanceof StandardException) {
-					t = ((StandardException) t).getNestedException();
-					continue;
-				}
-				break;
-			}
+			FAIL(t.toString());
+			t.printStackTrace(out.getPrintWriter());
 			return false;
 		}
 



Mime
View raw message