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-863 NPE when invoking proxy for custom jsf converter
Date Mon, 23 Mar 2015 18:16:58 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 4edbca0ca -> 49c9a9eaf


DELTASPIKE-863 NPE when invoking proxy for custom jsf converter

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

Branch: refs/heads/master
Commit: 49c9a9eafd2aa69a0264a69eea388ad32fdaa803
Parents: 4edbca0
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Mon Mar 23 19:16:48 2015 +0100
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Mon Mar 23 19:16:48 2015 +0100

----------------------------------------------------------------------
 .../core/util/proxy/AsmProxyClassGenerator.java | 31 ++++++++++++++++++--
 .../DeltaSpikeProxyContextualLifecycle.java     | 12 ++++++--
 2 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/49c9a9ea/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/AsmProxyClassGenerator.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/AsmProxyClassGenerator.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/AsmProxyClassGenerator.java
index a615372..e1f8394 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/AsmProxyClassGenerator.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/AsmProxyClassGenerator.java
@@ -111,7 +111,8 @@ public abstract class AsmProxyClassGenerator
         }
 
         defineInvocationHandlerField(cw, invocationHandlerType);
-        defineConstructor(cw, proxyType, superType);
+        defineDefaultConstructor(cw, proxyType, superType);
+        defineDelegateInvocationHandlerConstructor(cw, proxyType, superType, invocationHandlerType);
         defineDeltaSpikeProxyMethods(cw, proxyType, invocationHandlerType);
 
         for (java.lang.reflect.Method method : delegateMethods)
@@ -136,7 +137,7 @@ public abstract class AsmProxyClassGenerator
                 invocationHandlerType.getDescriptor(), null, null).visitEnd();
     }
 
-    private static void defineConstructor(ClassWriter cw, Type proxyType, Type superType)
+    private static void defineDefaultConstructor(ClassWriter cw, Type proxyType, Type superType)
     {
         GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC,
                 new Method("<init>", Type.VOID_TYPE, new Type[]{ }),
@@ -154,6 +155,32 @@ public abstract class AsmProxyClassGenerator
 
         mg.visitEnd();
     }
+    
+    private static void defineDelegateInvocationHandlerConstructor(ClassWriter cw, Type proxyType,
Type superType,
+            Type invocationHandlerType)
+    {
+        GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC,
+                new Method("<init>", Type.VOID_TYPE, new Type[] { invocationHandlerType
}),
+                null,
+                null,
+                cw);
+
+        mg.visitCode();
+
+        // invoke super constructor
+        mg.loadThis();
+        mg.invokeConstructor(superType, Method.getMethod("void <init> ()"));
+        
+        // set invocation handler
+        mg.loadThis();
+        mg.loadArg(0);
+        mg.putField(proxyType, FIELDNAME_DELEGATE_INVOCATION_HANDLER, invocationHandlerType);
+        
+        mg.returnValue();
+        mg.endMethod();
+
+        mg.visitEnd();
+    }
 
     private static void defineDeltaSpikeProxyMethods(ClassWriter cw, Type proxyType, Type
invocationHandlerType)
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/49c9a9ea/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/DeltaSpikeProxyContextualLifecycle.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/DeltaSpikeProxyContextualLifecycle.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/DeltaSpikeProxyContextualLifecycle.java
index 2932502..a9fb26d 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/DeltaSpikeProxyContextualLifecycle.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/proxy/DeltaSpikeProxyContextualLifecycle.java
@@ -18,6 +18,7 @@
  */
 package org.apache.deltaspike.core.util.proxy;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.util.Set;
 import javax.enterprise.context.Dependent;
@@ -60,12 +61,17 @@ public class DeltaSpikeProxyContextualLifecycle<T, H extends InvocationHandler>
     {
         try
         {
-            T instance = proxyClass.newInstance();
+            T instance;
 
-            if (delegateInvocationHandlerClass != null)
+            if (delegateInvocationHandlerClass == null)
+            {
+                instance = proxyClass.newInstance();
+            }
+            else
             {
                 H delegateInvocationHandler = instantiateDelegateInvocationHandler();
-                ((DeltaSpikeProxy) instance).setDelegateInvocationHandler(delegateInvocationHandler);
+                Constructor<T> constructor = proxyClass.getConstructor(delegateInvocationHandlerClass);
+                instance = constructor.newInstance(delegateInvocationHandler);
             }
 
             if (this.injectionTarget != null)


Mime
View raw message