Handle invocation target exceptions and throw the original exception when it happens
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 3 Jan 2009 01:25:56 +0000 (01:25 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 3 Jan 2009 01:25:56 +0000 (01:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@730884 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java

index da62ebb..2866538 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.apache.tomcat.jdbc.pool;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.sql.Connection;
 import java.sql.SQLException;
@@ -84,7 +85,16 @@ public class ProxyConnection extends JdbcInterceptor {
             return connection.getConnection();
         }
         if (isClosed()) throw new SQLException("Connection has already been closed.");
-        return method.invoke(connection.getConnection(),args);
+        try {
+            return method.invoke(connection.getConnection(),args);
+        }catch (Throwable t) {
+            if (t instanceof InvocationTargetException) {
+                InvocationTargetException it = (InvocationTargetException)t;
+                throw it.getCause()!=null?it.getCause():it;
+            } else {
+                throw t;
+            }
+        }
     }
     
     public boolean isClosed() {
index 70993aa..d2e6648 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.tomcat.jdbc.pool.interceptor;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.sql.CallableStatement;
@@ -231,7 +232,12 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce
                 result =  method.invoke(delegate,args);
             }catch (Throwable t) {
                 reportFailedQuery(query,args,name,start,t);
-                throw t;
+                if (t instanceof InvocationTargetException) {
+                    InvocationTargetException it = (InvocationTargetException)t;
+                    throw it.getCause()!=null?it.getCause():it;
+                } else {
+                    throw t;
+                }
             }
             //measure the time
             long delta = (process)?(System.currentTimeMillis()-start):Long.MIN_VALUE;