aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1352750 - in /aries/branches/org.apache.aries.proxy.impl-0.4.1/src: main/java/org/apache/aries/proxy/impl/ main/java/org/apache/aries/proxy/impl/gen/ test/java/org/apache/aries/blueprint/proxy/
Date Fri, 22 Jun 2012 01:56:55 GMT
Author: dkulp
Date: Fri Jun 22 01:56:54 2012
New Revision: 1352750

URL: http://svn.apache.org/viewvc?rev=1352750&view=rev
Log:
Port ARIES-861 to fixes branch

Added:
    aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java
Modified:
    aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
    aries/branches/org.apache.aries.proxy.impl-0.4.1/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java

Added: aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java
URL: http://svn.apache.org/viewvc/aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java?rev=1352750&view=auto
==============================================================================
--- aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java
(added)
+++ aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/ProxyUtils.java
Fri Jun 22 01:56:54 2012
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.proxy.impl;
+
+import java.math.BigDecimal;
+
+import org.objectweb.asm.Opcodes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProxyUtils
+{
+  private static Logger LOGGER = LoggerFactory.getLogger(ProxyUtils.class);
+  public static final int JAVA_CLASS_VERSION = new BigDecimal(System.getProperty("java.class.version")).intValue();
+  private static int weavingJavaVersion = -1; // initialise an invalid number
+  /**
+   * Get the java version to be woven at.
+   * @return
+   */
+  public static int getWeavingJavaVersion() {
+    if (weavingJavaVersion == -1 ) {
+      if (JAVA_CLASS_VERSION >= Opcodes.V1_7) {
+        LOGGER.debug("Weaving to Java 7");
+        weavingJavaVersion = Opcodes.V1_7;
+      } else if (JAVA_CLASS_VERSION == Opcodes.V1_6){
+        LOGGER.debug("Weaving to Java 6");
+        weavingJavaVersion = Opcodes.V1_6;
+      } else if (JAVA_CLASS_VERSION == Opcodes.V1_5) {
+        LOGGER.debug("Weaving to Java 5");
+        weavingJavaVersion = Opcodes.V1_5;
+      } // no need to list all Opcodes as Aries should only work with java5 or above.
+    } 
+    return weavingJavaVersion;
+  } 
+}

Modified: aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
URL: http://svn.apache.org/viewvc/aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java?rev=1352750&r1=1352749&r2=1352750&view=diff
==============================================================================
--- aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
(original)
+++ aries/branches/org.apache.aries.proxy.impl-0.4.1/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
Fri Jun 22 01:56:54 2012
@@ -19,8 +19,11 @@
 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;
 import org.objectweb.asm.Attribute;
 import org.objectweb.asm.ClassAdapter;
@@ -108,13 +111,14 @@ public class ProxySubclassAdapter extend
       throw new TypeNotPresentException(superclassBinaryName, cnfe);
     }
 
-    // move the existing class name to become the superclass
-    // modify the version of the dynamic subclass to be Java 1.6
-    int newVersion = Opcodes.V1_6;
-    // keep the same access and signature as the superclass
+    // keep the same access and signature as the superclass (unless it's abstract)
     // remove all the superclass interfaces because they will be inherited
     // from the superclass anyway
-    cv.visit(newVersion, access, newClassName, signature, name, null);
+    if((access & ACC_ABSTRACT) != 0) {
+      //If the super was abstract the subclass should not be!
+      access &= ~ACC_ABSTRACT;
+    }
+    cv.visit(ProxyUtils.getWeavingJavaVersion(), access, newClassName, signature, name, null);
 
     // add a private field for the invocation handler
     // this isn't static in case we have multiple instances of the same
@@ -137,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
});

Modified: aries/branches/org.apache.aries.proxy.impl-0.4.1/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/branches/org.apache.aries.proxy.impl-0.4.1/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java?rev=1352750&r1=1352749&r2=1352750&view=diff
==============================================================================
--- aries/branches/org.apache.aries.proxy.impl-0.4.1/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java
(original)
+++ aries/branches/org.apache.aries.proxy.impl-0.4.1/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java
Fri Jun 22 01:56:54 2012
@@ -164,6 +164,7 @@ 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(



Mime
View raw message