[jboss-cvs] JBossAS SVN: r57772 - in projects/aop/trunk/aop: . src/main/org/jboss/aop/proxy src/main/org/jboss/aop/util src/test/org/jboss/test/aop/bridgemethod src/test/org/jboss/test/aop/bridgemethod/notwoven

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Oct 22 13:10:41 EDT 2006


Author: stalep
Date: 2006-10-22 13:10:26 -0400 (Sun, 22 Oct 2006)
New Revision: 57772

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/notwoven/BridgeMethodTestCase.java
Removed:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/BridgeMethodTestCase.java
Modified:
   projects/aop/trunk/aop/base-tests.xml
   projects/aop/trunk/aop/build-tests-jdk14.xml
   projects/aop/trunk/aop/build-tests-jdk50.xml
   projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/ClassProxyFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/util/JavassistMethodHashing.java
Log:
[JBAOP-255]
We have to check if we try to add a bridge method to the proxy
and ignore it and all superimplementations of it.

Modified: projects/aop/trunk/aop/base-tests.xml
===================================================================
--- projects/aop/trunk/aop/base-tests.xml	2006-10-22 16:56:31 UTC (rev 57771)
+++ projects/aop/trunk/aop/base-tests.xml	2006-10-22 17:10:26 UTC (rev 57772)
@@ -70,6 +70,9 @@
       <antcall target="${test-target}" inheritRefs="true">
          <param name="test" value="field"/>
       </antcall>
+      <antcall target="${test-target}" inheritRefs="true">
+         <param name="test" value="bridgemethod"/>
+      </antcall>
 
       <!-- Tests with special requirements for parameters -->
       <antcall target="${test-target}" inheritRefs="true">
@@ -87,4 +90,4 @@
       <echo message="The project fragment which executes the main tests"/>
    </target>
    
-</project>
\ No newline at end of file
+</project>

Modified: projects/aop/trunk/aop/build-tests-jdk14.xml
===================================================================
--- projects/aop/trunk/aop/build-tests-jdk14.xml	2006-10-22 16:56:31 UTC (rev 57771)
+++ projects/aop/trunk/aop/build-tests-jdk14.xml	2006-10-22 17:10:26 UTC (rev 57772)
@@ -225,6 +225,7 @@
          <classpath refid="javac.classpath"/>
          <include name="**/*.java"/>
          <exclude name="org/jboss/test/aop/memoryleaks/**/*.java"/>
+         <exclude name="org/jboss/test/aop/bridgemethod/*.java"/>
       </javac>
    </target>
 

Modified: projects/aop/trunk/aop/build-tests-jdk50.xml
===================================================================
--- projects/aop/trunk/aop/build-tests-jdk50.xml	2006-10-22 16:56:31 UTC (rev 57771)
+++ projects/aop/trunk/aop/build-tests-jdk50.xml	2006-10-22 17:10:26 UTC (rev 57772)
@@ -650,6 +650,7 @@
       <echo>org/jboss/test/aop/methodhashing/MethodHashingTestCase will fail until the microcontainer has been updated in the repository</echo>
 
       <junit printsummary="yes" fork="no" haltonfailure="no" >
+         <sysproperty key="jboss.aop.debug.classes" value="false"/>
          <classpath>
             <path refid="javac.classpath"/>
             <pathelement location="${build.tests.classes}"/>
@@ -667,7 +668,7 @@
 		         <include name="org/jboss/test/aop/proxy/ProxyTestCase.class"/>
       		   <include name="org/jboss/test/aop/methodhashing/MethodHashingTestCase.class"/>
       		   <include name="org/jboss/test/aop/annotationc/AnnotationTester.class"/>
-      		   <include name="org/jboss/test/aop/methodoverride/MethodOverrideTestCase.class"/>
+      		   <include name="org/jboss/test/aop/bridgemethod/notwoven/BridgeMethodTestCase.class"/>
 		      </fileset>
 		   </batchtest>
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/ClassProxyFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/ClassProxyFactory.java	2006-10-22 16:56:31 UTC (rev 57771)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/ClassProxyFactory.java	2006-10-22 17:10:26 UTC (rev 57772)
@@ -24,10 +24,13 @@
 import java.lang.ref.WeakReference;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.WeakHashMap;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.ClassAdvisor;
@@ -140,13 +143,12 @@
 
       CtClass template = pool.get("org.jboss.aop.proxy.ClassProxyTemplate");
       CtClass superclass = pool.get(clazz.getName());
-
+      
       CtField mixinField = template.getField("mixins");
       CtField instanceAdvisor = template.getField("instanceAdvisor");
-
-
+      
       CtClass proxy = TransformerCommon.makeClass(pool, classname, superclass);
-
+      
       mixinField = new CtField(mixinField.getType(), "mixins", proxy);
       mixinField.setModifiers(Modifier.PRIVATE);
       proxy.addField(mixinField);
@@ -308,37 +310,51 @@
    {
       CtClass proxy = createProxyCtClass(mixins, clazz);
       Class proxyClass = TransformerCommon.toClass(proxy);
-      Map methodmap = ClassProxyFactory.getMethodMap(proxyClass);
+      Map methodmap = ClassProxyFactory.getMethodMap(proxyClass); 
       Field field = proxyClass.getDeclaredField("methodMap");
       SecurityActions.setAccessible(field);
       field.set(null, methodmap);
       return proxyClass;
    }
 
-   private static void populateMethodTables(HashMap advised, Class superclass)
+   private static void populateMethodTables(HashMap advised, List ignoredHash, Class superclass)
    throws Exception
    {
       if (superclass == null) return;
       if (superclass.getName().equals("java.lang.Object")) return;
 
-      populateMethodTables(advised, superclass.getSuperclass());
-
       Method[] declaredMethods = superclass.getDeclaredMethods();
       for (int i = 0; i < declaredMethods.length; i++)
       {
-         if (ClassAdvisor.isAdvisable(declaredMethods[i]))
-         {
-            long hash = org.jboss.aop.util.MethodHashing.methodHash(declaredMethods[i]);
-            advised.put(new Long(hash), new MethodPersistentReference(declaredMethods[i], PersistentReference.REFERENCE_SOFT));
+         if (ClassAdvisor.isAdvisable(declaredMethods[i])) 
+         {   
+            //if a method is marked as a "volatile/bridge" method, we need to
+            //ignore it and check that other implementations of that method
+            // (in superclasses) are not added either.
+            if(!java.lang.reflect.Modifier.isVolatile( declaredMethods[i].getModifiers()))
+            {
+               long hash = org.jboss.aop.util.MethodHashing.methodHash(declaredMethods[i]);
+               if(!ignoredHash.contains(new Long(hash)))
+                  advised.put(new Long(hash), new MethodPersistentReference(declaredMethods[i], PersistentReference.REFERENCE_SOFT));
+            }
+            else
+            {
+               long hash = org.jboss.aop.util.MethodHashing.methodHash(declaredMethods[i]);
+               ignoredHash.add(new Long(hash));
+            }
          }
       }
+      
+      populateMethodTables(advised, ignoredHash, superclass.getSuperclass());
+
    }
 
    public static HashMap methodMap(Class clazz)
    throws Exception
    {
       HashMap methods = new HashMap();
-      populateMethodTables(methods, clazz);
+      List ignoredHash = new ArrayList();
+      populateMethodTables(methods, ignoredHash, clazz);
       return methods;
    }
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/util/JavassistMethodHashing.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/util/JavassistMethodHashing.java	2006-10-22 16:56:31 UTC (rev 57771)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/util/JavassistMethodHashing.java	2006-10-22 17:10:26 UTC (rev 57772)
@@ -24,6 +24,7 @@
 import javassist.CtClass;
 import javassist.CtConstructor;
 import javassist.CtMethod;
+import javassist.Modifier;
 import javassist.NotFoundException;
 
 
@@ -33,7 +34,9 @@
 import java.security.DigestOutputStream;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 
 /**
  * Create a unique hash for method.  This is the same as
@@ -144,39 +147,53 @@
       }
    }
    
-   private static void addDeclaredMethods(HashMap advised, CtClass superclass) throws Exception
+   private static void addDeclaredMethods(HashMap advised, List ignoredHash, CtClass superclass) throws Exception
    {
       CtMethod[] declaredMethods = superclass.getDeclaredMethods();
       for (int i = 0; i < declaredMethods.length; i++)
       {
          if (superclass.isInterface() || Advisable.isAdvisable(declaredMethods[i]))
          {
+            //if a method is marked as a "volatile/bridge" method, we need to
+            //ignore it and check that other implementations of that method
+            // (in superclasses) are not added either.
+            if(!Modifier.isVolatile(declaredMethods[i].getModifiers()))
+            {
             long hash = methodHash(declaredMethods[i]);
-            advised.put(new Long(hash), declaredMethods[i]);
+            if(!ignoredHash.contains(new Long(hash)))
+               advised.put(new Long(hash), declaredMethods[i]);
+            }
+            else
+            {
+               long hash = methodHash(declaredMethods[i]);
+               ignoredHash.add(new Long(hash));
+            }
          }
       }
    }
-   private static void populateMethodTables(HashMap advised, CtClass superclass)
+   private static void populateMethodTables(HashMap advised, List ignoredHash, CtClass superclass)
       throws Exception
    {
       if (superclass == null) return;
       if (superclass.getName().equals("java.lang.Object")) return;
 
-      populateMethodTables(advised, superclass.getSuperclass());
-      addDeclaredMethods(advised, superclass);
+      addDeclaredMethods(advised, ignoredHash, superclass);
+      populateMethodTables(advised, ignoredHash, superclass.getSuperclass());
    }
 
    public static HashMap getMethodMap(CtClass clazz) throws Exception
    {
       HashMap map = new HashMap();
-      populateMethodTables(map, clazz);
+      List ignoredHash = new ArrayList();
+      populateMethodTables(map, ignoredHash, clazz);
       return map;
    }
 
    public static HashMap getDeclaredMethodMap(CtClass clazz) throws Exception
    {
       HashMap map = new HashMap();
-      addDeclaredMethods(map, clazz);
+      List ignoredHash = new ArrayList();
+      addDeclaredMethods(map, ignoredHash, clazz);
       return map;
    }
 

Deleted: projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/BridgeMethodTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/BridgeMethodTestCase.java	2006-10-22 16:56:31 UTC (rev 57771)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/BridgeMethodTestCase.java	2006-10-22 17:10:26 UTC (rev 57772)
@@ -1,108 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.test.aop.bridgemethod;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-import org.jboss.aop.proxy.ClassProxyFactory;
-import org.jboss.test.aop.AOPTestWithSetup;
-
-/**
- * Test that we handle bridgemethods created by the java15 compiler correctly
- * regarding reflection.
- *
- * @author <a href="mailto:stalep at conduct.no">Stale W. Pedersen</a>
- * @version $Revision
- */
-public class BridgeMethodTestCase extends AOPTestWithSetup
-{
-   
-   public static void main(String[] args)
-   {
-      TestRunner.run(suite());
-   }
-
-   public static Test suite()
-   {
-      TestSuite suite = new TestSuite("BridgeMethodTestCase");
-      suite.addTestSuite(BridgeMethodTestCase.class);
-      return suite;
-   }
-
-   public BridgeMethodTestCase(String name)
-   {
-      super(name);
-   }
-
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-   }
-   
-   public void testMethod()
-   {
-      try {
-         ClassProxyFactory.newInstance(POJO.class);
-         assertTrue("ClassProxy failed to instrument class", true);
-      }
-      catch(Exception e)
-      {
-         System.out.println("ERROR: "+e.getMessage());
-         e.printStackTrace();
-         assertTrue("ClassProxy failed to instrument class", false);
-         
-      }
-     
-   }
-   
-   public void testGenericMethod()
-   {
-      try {
-         SuperPOJO superPojo = (SuperPOJO) ClassProxyFactory.newInstance(SubPOJO.class);
-         assertTrue("ClassProxy failed to instrument generic class", true);
-      }
-      catch(Exception e)
-      {
-         System.out.println("ERROR: "+e.getMessage());
-         e.printStackTrace();
-         assertTrue("ClassProxy failed to instrument generic class", false);
-         
-      }
-   }
-   
-   public void testMethodOverride()
-   {
-      try {
-         ClassProxyFactory.newInstance(SubPOJO2.class);
-         assertTrue("ClassProxy failed to instrument overrided class", true);
-      }
-      catch(Exception e)
-      {
-         System.out.println("ERROR: "+e.getMessage());
-         e.printStackTrace();
-         assertTrue("ClassProxy failed to instrument overrided class", false); 
-      }
-   }
-
-}
\ No newline at end of file

Copied: projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/notwoven/BridgeMethodTestCase.java (from rev 57770, projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/BridgeMethodTestCase.java)
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/BridgeMethodTestCase.java	2006-10-22 16:49:26 UTC (rev 57770)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/bridgemethod/notwoven/BridgeMethodTestCase.java	2006-10-22 17:10:26 UTC (rev 57772)
@@ -0,0 +1,112 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.aop.bridgemethod.notwoven;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.aop.proxy.ClassProxyFactory;
+import org.jboss.test.aop.AOPTestWithSetup;
+import org.jboss.test.aop.bridgemethod.POJO;
+import org.jboss.test.aop.bridgemethod.SubPOJO;
+import org.jboss.test.aop.bridgemethod.SubPOJO2;
+import org.jboss.test.aop.bridgemethod.SuperPOJO;
+
+/**
+ * Test that we handle bridgemethods created by the java15 compiler correctly
+ * regarding reflection.
+ *
+ * @author <a href="mailto:stalep at conduct.no">Stale W. Pedersen</a>
+ * @version $Revision
+ */
+public class BridgeMethodTestCase extends AOPTestWithSetup
+{
+   
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("BridgeMethodTestCase");
+      suite.addTestSuite(BridgeMethodTestCase.class);
+      return suite;
+   }
+
+   public BridgeMethodTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+   }
+   
+   public void testMethod()
+   {
+      try {
+         ClassProxyFactory.newInstance(POJO.class);
+         assertTrue("ClassProxy failed to instrument class", true);
+      }
+      catch(Exception e)
+      {
+         System.out.println("ERROR: "+e.getMessage());
+         e.printStackTrace();
+         assertTrue("ClassProxy failed to instrument class", false);
+         
+      }
+     
+   }
+   
+   public void testGenericMethod()
+   {
+      try {
+         SuperPOJO superPojo = (SuperPOJO) ClassProxyFactory.newInstance(SubPOJO.class);
+         assertTrue("ClassProxy failed to instrument generic class", true);
+      }
+      catch(Exception e)
+      {
+         System.out.println("ERROR: "+e.getMessage());
+         e.printStackTrace();
+         assertTrue("ClassProxy failed to instrument generic class", false);
+         
+      }
+   }
+   
+   public void testMethodOverride()
+   {
+      try {
+         ClassProxyFactory.newInstance(SubPOJO2.class);
+         assertTrue("ClassProxy failed to instrument overrided class", true);
+      }
+      catch(Exception e)
+      {
+         System.out.println("ERROR: "+e.getMessage());
+         e.printStackTrace();
+         assertTrue("ClassProxy failed to instrument overrided class", false); 
+      }
+   }
+
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list