aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1352698 - in /aries/branches/proxy-0.3.x/proxy-impl/src: main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java
Date Thu, 21 Jun 2012 21:23:16 GMT
Author: dkulp
Date: Thu Jun 21 21:23:15 2012
New Revision: 1352698

URL: http://svn.apache.org/viewvc?rev=1352698&view=rev
Log:
[ARIES-861] Backport fix for jdk 1.6.0_u33

Modified:
    aries/branches/proxy-0.3.x/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
    aries/branches/proxy-0.3.x/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java

Modified: aries/branches/proxy-0.3.x/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
URL: http://svn.apache.org/viewvc/aries/branches/proxy-0.3.x/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java?rev=1352698&r1=1352697&r2=1352698&view=diff
==============================================================================
--- aries/branches/proxy-0.3.x/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
(original)
+++ aries/branches/proxy-0.3.x/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
Thu Jun 21 21:23:15 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.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.Attribute;
@@ -139,7 +141,20 @@ public class ProxySubclassAdapter extend
     }
     // 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
});

Modified: aries/branches/proxy-0.3.x/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/branches/proxy-0.3.x/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java?rev=1352698&r1=1352697&r2=1352698&view=diff
==============================================================================
--- aries/branches/proxy-0.3.x/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java
(original)
+++ aries/branches/proxy-0.3.x/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java
Thu Jun 21 21:23:15 2012
@@ -307,12 +307,12 @@ public class ProxySubclassGeneratorTest
    * Test a private constructor
    */
   @Test
+  @org.junit.Ignore("Failes on JDK's 1.6.0_u33 and newer as you cannot call a private constructor
from subclass")
   public void testPrivateConstructor() throws Exception
   {
     Object o = ProxySubclassGenerator.newProxySubclassInstance(
         ProxyTestClassPrivateConstructor.class, ih);
     assertNotNull("The new instance was null", o);
-
   }
   
 //  /**



Mime
View raw message