db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1574425 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/error/ engine/org/apache/derby/impl/services/reflect/ engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/tools/
Date Wed, 05 Mar 2014 11:06:11 GMT
Author: kahatlen
Date: Wed Mar  5 11:06:10 2014
New Revision: 1574425

URL: http://svn.apache.org/r1574425
Log:
DERBY-6493: Improve reporting of exceptions wrapped in InvocationTargetException

Unwrap InvocationTargetException and PrivilegedActionException before
reporting them so that it is easier to see what the real error is.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/ReflectMethod.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportProcedureTest.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?rev=1574425&r1=1574424&r2=1574425&view=diff
==============================================================================
--- 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 Wed
Mar  5 11:06:10 2014
@@ -21,6 +21,8 @@
 
 package org.apache.derby.iapi.error;
 
+import java.lang.reflect.InvocationTargetException;
+import java.security.PrivilegedActionException;
 import java.sql.SQLException;
 import java.sql.SQLWarning;
 
@@ -372,9 +374,38 @@ public class StandardException extends E
                 ? (StandardException) cause : null;
 	}
 
+    /**
+     * Check if the top-level throwable is just a vacuous wrapper that does
+     * not carry any useful information except what's returned by the
+     * {@link Throwable#getCause()} method.
+     *
+     * @param t the throwable to check
+     * @return {@code true} if the throwable is a vacuous wrapper and the
+     *   only useful piece of information is the cause, or {@code false}
+     *   otherwise
+     */
+    private static boolean isVacuousWrapper(Throwable t) {
+        // The only interesting information in an InvocationTargetException
+        // or a PrivilegedActionException is the cause, so consider them
+        // vacuous if they have a cause.
+        if (t instanceof InvocationTargetException
+                || t instanceof PrivilegedActionException) {
+            return (t.getCause() != null);
+        }
+
+        // All other exceptions are non-vacuous.
+        return false;
+    }
 
 	public static StandardException unexpectedUserException(Throwable t)
 	{
+
+        // If there is no useful information in the top-level throwable,
+        // peel it off and only report the cause.
+        if (isVacuousWrapper(t)) {
+            return unexpectedUserException(t.getCause());
+        }
+
         // If the exception is an SQLException generated by Derby, it has an
         // argument ferry which is a StandardException. Use this to check
         // whether the exception was generated by Derby.
@@ -487,6 +518,12 @@ public class StandardException extends E
 
 	public static StandardException plainWrapException(Throwable t) {
 
+        // If there is no useful information in the top-level throwable,
+        // peel it off and only report the cause.
+        if (isVacuousWrapper(t)) {
+            return plainWrapException(t.getCause());
+        }
+
 		if (t instanceof StandardException)
 			return (StandardException) t;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/ReflectMethod.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/ReflectMethod.java?rev=1574425&r1=1574424&r2=1574425&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/ReflectMethod.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/ReflectMethod.java
Wed Mar  5 11:06:10 2014
@@ -55,9 +55,8 @@ class ReflectMethod implements Generated
 
 		} catch (InvocationTargetException ite) {
 
-			t = ite.getTargetException();
-			if (t instanceof StandardException)
-				throw (StandardException) t;
+            t = ite;
+
 		}
 		
 		throw StandardException.unexpectedUserException(t);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=1574425&r1=1574424&r2=1574425&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Wed Mar
 5 11:06:10 2014
@@ -849,13 +849,6 @@ class FromVTI extends FromTable implemen
         }
 		catch(Throwable t)
 		{
-            if( t instanceof InvocationTargetException)
-            {
-                InvocationTargetException ite = (InvocationTargetException) t;
-                Throwable wrappedThrowable = ite.getTargetException();
-                if( wrappedThrowable instanceof StandardException)
-                    throw (StandardException) wrappedThrowable;
-            }
 			throw StandardException.unexpectedUserException(t);
 		}
     } // end of getNewInstance

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportProcedureTest.java?rev=1574425&r1=1574424&r2=1574425&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportProcedureTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportProcedureTest.java
Wed Mar  5 11:06:10 2014
@@ -24,10 +24,7 @@ package org.apache.derbyTesting.function
 
 import java.sql.CallableStatement;
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLWarning;
 import java.sql.Statement;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
@@ -44,6 +41,8 @@ import junit.framework.TestSuite;
  */
 public class ImportExportProcedureTest extends BaseJDBCTestCase {
 
+    private static final String INVALID_DELIMITER = "XIE0J";
+
     /**
      * Public constructor required for running test as standalone JUnit.
      */
@@ -2125,12 +2124,12 @@ public class ImportExportProcedureTest e
         cSt = prepareCall(
             "call SYSCS_UTIL.SYSCS_IMPORT_TABLE ('IEP', 'T1' , "
             + "'extinout/t1.dat' , '', ';', null, 0) ");
-        assertStatementError("38000", cSt);
+        assertStatementError(INVALID_DELIMITER, cSt);
         
         cSt = prepareCall(
             " call SYSCS_UTIL.SYSCS_IMPORT_TABLE ('IEP', 'T1' , "
             + "'extinout/t1.dat' , null, '', null, 0) ");
-        assertStatementError("38000", cSt);
+        assertStatementError(INVALID_DELIMITER, cSt);
         
         //same delimter can not be used as character and column 
         // delimters
@@ -2138,7 +2137,7 @@ public class ImportExportProcedureTest e
         cSt = prepareCall(
             "call SYSCS_UTIL.SYSCS_IMPORT_TABLE ('IEP', 'T1' , "
             + "'extinout/t1.dat' , ';', ';', null, 1) ");
-        assertStatementError("38000", cSt);
+        assertStatementError(INVALID_DELIMITER, cSt);
         
         Connection conn = getConnection();
         conn.setAutoCommit(false);



Mime
View raw message