[jboss-cvs] JBossAS SVN: r70618 - in projects/aop/trunk/aop/src/main/org/jboss/aop: reflection and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 10 09:16:21 EDT 2008


Author: stalep
Date: 2008-03-10 09:16:20 -0400 (Mon, 10 Mar 2008)
New Revision: 70618

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationElement.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/reflection/ReflectionAspect.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/util/ReflectUtils.java
Log:
[JBAOP-532] Fixed a bug with jdk1.4 where javassist would check bytecode generated methods for annotations (eg access$1). these methods should be ignored.

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationElement.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationElement.java	2008-03-10 12:11:31 UTC (rev 70617)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/annotation/AnnotationElement.java	2008-03-10 13:16:20 UTC (rev 70618)
@@ -30,6 +30,8 @@
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
+import org.jboss.aop.util.ReflectUtils;
+
 /**
  * Bridge/portability class for resolving annotations in JDK 1.4 and JDK1.5
  * Should be usable in JDK 1.4 and also should support finding invisible annotations.
@@ -435,6 +437,10 @@
 
          public Annotation[] getVisibleAnnotations(Method m)
          {
+            if (m.getName().startsWith("access$") && !ReflectUtils.isNotAccessMethod(m))
+            {
+               return new Annotation[0];
+            }
             return m.getAnnotations();
          }
          
@@ -690,6 +696,10 @@
                return AccessController.doPrivileged(new PrivilegedExceptionAction<Annotation[]>(){
                   public Annotation[] run() throws Exception
                   {
+                     if (m.getName().startsWith("access$") && !ReflectUtils.isNotAccessMethod(m))
+                     {
+                        return new Annotation[0];
+                     }
                      return m.getAnnotations();
                   }
                });

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/reflection/ReflectionAspect.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/reflection/ReflectionAspect.java	2008-03-10 12:11:31 UTC (rev 70617)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/reflection/ReflectionAspect.java	2008-03-10 13:16:20 UTC (rev 70618)
@@ -36,6 +36,7 @@
 import org.jboss.aop.joinpoint.MethodCalledByConstructorInvocation;
 import org.jboss.aop.joinpoint.MethodCalledByMethodInvocation;
 import org.jboss.aop.util.MethodHashing;
+import org.jboss.aop.util.ReflectUtils;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
@@ -81,8 +82,6 @@
    private static Pattern fieldSetPattern =
    Pattern.compile("set(|Boolean|Byte|Char|Double|Float|Int|Long|Short)?");
 
-   private static Pattern accessMethodPattern = Pattern.compile("access[$](\\d)+");
-   
    // Constructors --------------------------------------------------
    
    public ReflectionAspect()
@@ -874,7 +873,7 @@
          for (int i = 0; i < advisedMethods.length; i++)
          {
             Method m = (Method) advisedMethods[i];
-            if (clazz.equals(m.getDeclaringClass()) && isNotAccessMethod(m) && isNotJavassistWrappedMethod(m))
+            if (clazz.equals(m.getDeclaringClass()) && ReflectUtils.isNotAccessMethod(m) && isNotJavassistWrappedMethod(m))
             {
                methods.add(m);
             }
@@ -901,7 +900,7 @@
          for (int i = 0; i < advisedMethods.length; i++)
          {
             Method m = (Method) advisedMethods[i];
-            if (m.equals(method) && isNotAccessMethod(m) && isNotJavassistWrappedMethod(m))
+            if (m.equals(method) && ReflectUtils.isNotAccessMethod(m) && isNotJavassistWrappedMethod(m))
             {
                return method;
             }
@@ -911,30 +910,6 @@
       throw new NoSuchMethodException();
    }
 
-   
-   /**
-    * Java adds a few static void methods called access$0, access$1 etc. when inner classes are used
-    *
-    * @return true if this method is static, void, has package access and has a name like access$0, access$1 etc.
-    */
-   private boolean isNotAccessMethod(Method m)
-   {
-
-      //TODO: Normally access methods should return void, but having optimised field invocation
-      //it seems that javassist occasionally creates these methods with other return types
-
-      if (Modifier.isStatic(m.getModifiers()))
-      {
-         Matcher match = accessMethodPattern.matcher(m.getName());
-         if (match.matches())
-         {
-            return false;
-         }
-      }
-
-      return true;
-   }
-
    private boolean isNotJavassistWrappedMethod(Method m)
    {
       if (Modifier.isPrivate(m.getModifiers()) && !Modifier.isStatic(m.getModifiers()))

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/util/ReflectUtils.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/util/ReflectUtils.java	2008-03-10 12:11:31 UTC (rev 70617)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/util/ReflectUtils.java	2008-03-10 13:16:20 UTC (rev 70618)
@@ -22,7 +22,10 @@
 package org.jboss.aop.util;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * 
@@ -32,6 +35,7 @@
 public class ReflectUtils
 {
    public static Class[] EMPTY_CLASS_ARRAY = new Class[0];
+   private static Pattern accessMethodPattern = Pattern.compile("access[$](\\d)+");
    
    public static Method[] getMethodsWithName(Class clazz, String name)
    {
@@ -58,4 +62,26 @@
       return (Method[])foundMethods.toArray(new Method[foundMethods.size()]);
    }
    
+   /**
+    * Java adds a few static void methods called access$0, access$1 etc. when inner classes are used
+    *
+    * @return false if this method is static, void, has package access and has a name like access$0, access$1 etc.
+    */
+   public static boolean isNotAccessMethod(Method m)
+   {
+
+      //TODO: Normally access methods should return void, but having optimised field invocation
+      //it seems that javassist occasionally creates these methods with other return types
+      if (Modifier.isStatic(m.getModifiers()))
+      {
+         Matcher match = accessMethodPattern.matcher(m.getName());
+         if (match.matches())
+         {
+            return false;
+         }
+      }
+
+      return true;
+   }
+   
 }




More information about the jboss-cvs-commits mailing list