[jboss-cvs] JBossAS SVN: r90518 - in projects/aop/branches/Branch_2_1_IBM/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
Tue Jun 23 08:28:39 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-06-23 08:28:39 -0400 (Tue, 23 Jun 2009)
New Revision: 90518

Added:
   projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java
Modified:
   projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/instrument/JoinPointGenerator.java
Log:
[JBAOP-740] More workarounds for IBMs Class.getDeclaringClass() implementation

Modified: projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/instrument/JoinPointGenerator.java	2009-06-23 12:24:51 UTC (rev 90517)
+++ projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/instrument/JoinPointGenerator.java	2009-06-23 12:28:39 UTC (rev 90518)
@@ -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;
@@ -497,6 +498,7 @@
          joinpointField = advisorClass.getField(joinpointFieldName);
          SecurityActions.setAccessible(joinpointField);
          joinpointFqn = advisorClass.getDeclaringClass().getName() + "$" + joinpointClassName;
+//         joinpointFqn = GetDeclaringClassUtil.getDeclaringClass(advisorClass).getName() + "$" + joinpointClassName;
       }
       catch (NoSuchFieldException e)
       {

Added: projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java
===================================================================
--- projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java	                        (rev 0)
+++ projects/aop/branches/Branch_2_1_IBM/aop/src/main/java/org/jboss/aop/util/GetDeclaringClassUtil.java	2009-06-23 12:28:39 UTC (rev 90518)
@@ -0,0 +1,106 @@
+/*
+* 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
+   {
+      //Better way to determine this
+      isIBMJVM = true;
+   }
+   
+   public static Class<?> getDeclaringClass(Class<?> clazz)
+   {
+      if (clazz == null)
+      {
+         throw new IllegalArgumentException("Null class");
+      }
+      Class<?> declaring = clazz.getDeclaringClass();
+      
+      if (declaring == null)
+      {
+         int last = clazz.getName().lastIndexOf('$');
+         if (last >= 0)
+         {
+            try
+            {
+               ClassLoader cl = getClassLoader(clazz);
+               declaring = cl.loadClass(clazz.getName().substring(0, last));
+            }
+            catch (ClassNotFoundException e)
+            {
+               throw new RuntimeException(e);
+            }
+         }
+      }
+      
+      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);
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list