deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-420 fixed proxy exception passthrough handling
Date Sat, 14 Mar 2015 15:16:53 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 72c9c81f7 -> 9a567b1d3


DELTASPIKE-420 fixed proxy exception passthrough handling

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/9a567b1d
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/9a567b1d
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/9a567b1d

Branch: refs/heads/master
Commit: 9a567b1d32f36bf810e9cce5d774856106365fdc
Parents: 72c9c81
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Sat Mar 14 16:16:44 2015 +0100
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Sat Mar 14 16:16:44 2015 +0100

----------------------------------------------------------------------
 .../impl/proxy/AsmProxyClassGenerator.java      | 42 +++++++++++++++-----
 .../proxy/CallSuperManualInvocationHandler.java | 13 +++++-
 .../api/partialbean/uc006/AbstractSuper.java    |  2 +-
 3 files changed, 43 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9a567b1d/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/AsmProxyClassGenerator.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/AsmProxyClassGenerator.java
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/AsmProxyClassGenerator.java
index b877e01..1ac77f7 100644
--- a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/AsmProxyClassGenerator.java
+++ b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/AsmProxyClassGenerator.java
@@ -21,6 +21,7 @@ package org.apache.deltaspike.partialbean.impl.proxy;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.UndeclaredThrowableException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import javax.enterprise.inject.Typed;
 import org.objectweb.asm.ClassWriter;
@@ -212,12 +213,24 @@ public abstract class AsmProxyClassGenerator
             Class manualInvocationHandlerClass)
     {
         Type methodType = Type.getType(method);
-        Type[] exceptionTypes = getTypes(method.getExceptionTypes());
-
+        
+        ArrayList<Type> exceptionsToCatch = new ArrayList<Type>();
+        for (Class<?> exception : method.getExceptionTypes())
+        {
+            if (!RuntimeException.class.isAssignableFrom(exception))
+            {
+                exceptionsToCatch.add(Type.getType(exception));
+            }
+        }
+        
         // push the method definition
         int modifiers = (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED) & method.getModifiers();
         Method asmMethod = Method.getMethod(method);
-        GeneratorAdapter mg = new GeneratorAdapter(modifiers, asmMethod, null, exceptionTypes,
cw);
+        GeneratorAdapter mg = new GeneratorAdapter(modifiers,
+                asmMethod,
+                null,
+                getTypes(method.getExceptionTypes()),
+                cw);
 
         // copy annotations
         for (Annotation annotation : method.getDeclaredAnnotations())
@@ -240,23 +253,30 @@ public abstract class AsmProxyClassGenerator
         // cast the result
         mg.unbox(methodType.getReturnType());
 
+        // build try catch
+        Label tryBlockEnd = mg.mark();
+        
         // push return
         mg.returnValue();
 
-        // build try catch
-        Label tryBlockEnd = mg.mark();
-        boolean throwableCatched = false;
+        // catch runtime exceptions and rethrow it
+        Label rethrow = mg.mark();
+        mg.visitVarInsn(Opcodes.ASTORE, 1);
+        mg.visitVarInsn(Opcodes.ALOAD, 1);
+        mg.throwException();
+        mg.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrow, Type.getInternalName(RuntimeException.class));
 
-        // catch declared exceptions
-        if (exceptionTypes.length > 0)
+        // catch checked exceptions and rethrow it
+        boolean throwableCatched = false;
+        if (exceptionsToCatch.size() > 0)
         {
-            Label rethrow = mg.mark();
+            rethrow = mg.mark();
             mg.visitVarInsn(Opcodes.ASTORE, 1);
             mg.visitVarInsn(Opcodes.ALOAD, 1);
             mg.throwException();
 
             // catch declared exceptions and rethrow it...
-            for (Type exceptionType : exceptionTypes)
+            for (Type exceptionType : exceptionsToCatch)
             {
                 if (exceptionType.getClassName().equals(Throwable.class.getName()))
                 {
@@ -266,9 +286,9 @@ public abstract class AsmProxyClassGenerator
             }
         }
 
+        // if throwable isn't alreached cachted, catch it and wrap it with an UndeclaredThrowableException
and throw it
         if (!throwableCatched)
         {
-            // catch Throwable and wrap it with a UndeclaredThrowableException
             Type uteType = Type.getType(UndeclaredThrowableException.class);
             Label wrapAndRethrow = mg.mark();
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9a567b1d/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/CallSuperManualInvocationHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/CallSuperManualInvocationHandler.java
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/CallSuperManualInvocationHandler.java
index 86791d7..2f87849 100644
--- a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/CallSuperManualInvocationHandler.java
+++ b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/CallSuperManualInvocationHandler.java
@@ -18,6 +18,7 @@
  */
 package org.apache.deltaspike.partialbean.impl.proxy;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import javax.enterprise.inject.Typed;
 import org.apache.deltaspike.partialbean.impl.interception.AbstractManualInvocationHandler;
@@ -35,7 +36,15 @@ public class CallSuperManualInvocationHandler extends AbstractManualInvocationHa
     @Override
     protected Object proceedOriginal(Object proxy, Method method, Object[] parameters) throws
Throwable
     {
-        Method superAccessorMethod = PartialBeanProxyFactory.getSuperAccessorMethod(proxy,
method);
-        return superAccessorMethod.invoke(proxy, parameters);
+        try
+        {
+            Method superAccessorMethod = PartialBeanProxyFactory.getSuperAccessorMethod(proxy,
method);
+            return superAccessorMethod.invoke(proxy, parameters);
+        }
+        catch (InvocationTargetException e)
+        {
+            // rethrow original exception
+            throw e.getCause();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9a567b1d/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc006/AbstractSuper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc006/AbstractSuper.java
b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc006/AbstractSuper.java
index 8b1a8fd..d1fec16 100644
--- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc006/AbstractSuper.java
+++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc006/AbstractSuper.java
@@ -24,7 +24,7 @@ public abstract class AbstractSuper<T> extends AbstractSuperSuper
     public abstract T willFail2() throws Throwable;
 
     @Override
-    public String willFail3() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException
+    public String willFail3() throws RuntimeException, ClassNotFoundException, NoSuchMethodException,
NoSuchFieldException
     {
         return "willFail3";
     }


Mime
View raw message