aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1350390 - /aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
Date Thu, 14 Jun 2012 20:34:55 GMT
Author: dkulp
Date: Thu Jun 14 20:34:55 2012
New Revision: 1350390

URL: http://svn.apache.org/viewvc?rev=1350390&view=rev
Log:
[ARIES-861] We cannot call Object.super() as the verifier no longer
allows that.

Modified:
    aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java

Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java?rev=1350390&r1=1350389&r2=1350390&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
Thu Jun 14 20:34:55 2012
@@ -19,7 +19,9 @@
 package org.apache.aries.proxy.impl.gen;
 
 import java.io.IOException;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Modifier;
 
 import org.apache.aries.proxy.impl.ProxyUtils;
 import org.objectweb.asm.AnnotationVisitor;
@@ -139,9 +141,21 @@ public class ProxySubclassAdapter extend
       methodAdapter.invokeConstructor(Type.getType(superclassClass), new Method("<init>",
           Type.VOID_TYPE, NO_ARGS));
     }
-    // otherwise invoke the java.lang.Object no args constructor
     else {
-      methodAdapter.invokeConstructor(OBJECT_TYPE, new Method("<init>", Type.VOID_TYPE,
NO_ARGS));
+        try {
+            //if the superclass has a no-arg constructor that we can call, we need to call
it
+            // otherwise invoke the java.lang.Object no args constructor.  However, that
will fail 
+            // on the most recent versions of the JDK (1.6.0_u34 and 1.7.0_u5 and newer).
 For the
+            // newer JDK's, there is NOTHING we can do and the proxy will fail.
+            Constructor<?> cons = superclassClass.getDeclaredConstructor();
+            if (!Modifier.isPrivate(cons.getModifiers())) {
+                methodAdapter.invokeConstructor(Type.getType(superclassClass), new Method("<init>",
Type.VOID_TYPE, NO_ARGS));
+            } else {
+                methodAdapter.invokeConstructor(OBJECT_TYPE, new Method("<init>", Type.VOID_TYPE,
NO_ARGS));
+            }
+        } catch (Exception e) {
+            methodAdapter.invokeConstructor(OBJECT_TYPE, new Method("<init>", Type.VOID_TYPE,
NO_ARGS));
+        }
     }
     // call from the constructor to setInvocationHandler
     Method setter = new Method("setInvocationHandler", Type.VOID_TYPE, new Type[] { IH_TYPE
});



Mime
View raw message