[jboss-cvs] JBossAS SVN: r90560 - in projects/aop/trunk/aop/src/main/java/org/jboss/aop: util and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 24 11:34:44 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-06-24 11:34:44 -0400 (Wed, 24 Jun 2009)
New Revision: 90560

Added:
   projects/aop/trunk/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java
Modified:
   projects/aop/trunk/aop/src/main/java/org/jboss/aop/instrument/JoinPointGenerator.java
Log:
[JBAOP-740] Work around Class.getDeclaringClass() if on IBM JDK

Modified: projects/aop/trunk/aop/src/main/java/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/java/org/jboss/aop/instrument/JoinPointGenerator.java	2009-06-24 15:32:44 UTC (rev 90559)
+++ projects/aop/trunk/aop/src/main/java/org/jboss/aop/instrument/JoinPointGenerator.java	2009-06-24 15:34:44 UTC (rev 90560)
@@ -62,6 +62,7 @@
 import org.jboss.aop.joinpoint.JoinPointBean;
 import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
 import org.jboss.aop.pointcut.ast.ClassExpression;
+import org.jboss.aop.util.GetDeclaringClassUtil;
 import org.jboss.aop.util.JavassistUtils;
 import org.jboss.aop.util.ReflectToJavassist;
 import org.jboss.aop.util.logging.AOPLogger;
@@ -496,7 +497,7 @@
       {
          joinpointField = advisorClass.getField(joinpointFieldName);
          SecurityActions.setAccessible(joinpointField);
-         joinpointFqn = advisorClass.getDeclaringClass().getName() + "$" + joinpointClassName;
+         joinpointFqn = GetDeclaringClassUtil.getDeclaringClass(advisorClass).getName() + "$" + joinpointClassName;
       }
       catch (NoSuchFieldException e)
       {

Copied: projects/aop/trunk/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java (from rev 90558, projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java)
===================================================================
--- projects/aop/trunk/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java	2009-06-24 15:34:44 UTC (rev 90560)
@@ -0,0 +1,150 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.aop.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Utility class to work around IBM JDKs broken Class.getDeclaringClass() implementation
+ * when called on a generated class.
+ * See https://jira.jboss.org/jira/browse/JBPAPP-569 for a description
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class GetDeclaringClassUtil
+{
+   static final boolean isIBMJVM;
+   static
+   {
+      String vendor = getSystemProperty("java.vm.vendor");
+      isIBMJVM = vendor.toUpperCase().contains("IBM");
+   }
+   
+   public static Class<?> getDeclaringClass(Class<?> clazz)
+   {
+      if (clazz == null)
+      {
+         throw new IllegalArgumentException("Null class");
+      }
+      Class<?> declaring = clazz.getDeclaringClass();
+      
+      if (declaring == null && isIBMJVM)
+      {
+         String name = clazz.getName();
+         int last = name.lastIndexOf('$');
+         if (last >= 0)
+         {
+            ClassLoader cl = getClassLoader(clazz);
+            while (declaring == null && last >= 0)
+            {
+               try
+               {
+                  declaring = cl.loadClass(clazz.getName().substring(0, last));
+               }
+               catch(ClassNotFoundException e)
+               {
+                  last = name.lastIndexOf('$', last -1);
+               }
+            }
+            if (declaring == null)
+            {
+               throw new RuntimeException("No declaring class could be determined for " + clazz.getName());
+            }
+         }
+      }
+      
+      return declaring;
+   }
+   
+   private interface GetClassLoaderAction 
+   {
+      ClassLoader getClassLoader(Class<?> clazz);
+      
+      GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(Class<?> clazz)
+         {
+            return clazz.getClassLoader();
+         }};
+
+     GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(final Class<?> clazz)
+         {
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+               public ClassLoader run()
+               {
+                  return clazz.getClassLoader();
+               }});
+         }};
+   }
+   
+   private static ClassLoader getClassLoader(Class<?> clazz)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
+      }
+      else
+      {
+         return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+      }
+   }
+
+   private interface GetSystemPropertyAction 
+   {
+      String getSystemProperty(String key);
+      
+      GetSystemPropertyAction NON_PRIVILEGED = new GetSystemPropertyAction() {
+
+         public String getSystemProperty(String key)
+         {
+            return System.getProperty(key);
+         }};
+
+      GetSystemPropertyAction PRIVILEGED = new GetSystemPropertyAction() {
+
+         public String getSystemProperty(final String key)
+         {
+            return AccessController.doPrivileged(new PrivilegedAction<String>() {
+
+               public String run()
+               {
+                  return System.getProperty(key);
+               }});
+         }};
+   }
+   
+   private static String getSystemProperty(String key)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return GetSystemPropertyAction.NON_PRIVILEGED.getSystemProperty(key);
+      }
+      else
+      {
+         return GetSystemPropertyAction.PRIVILEGED.getSystemProperty(key);
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list