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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 19 18:06:38 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-06-19 18:06:38 -0400 (Tue, 19 Jun 2007)
New Revision: 63575

Added:
   projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/
   projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/BeforeAfterThrowingScopedTestCase.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJO.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/PerInstanceAspect.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/ThrownByTestException.java
Modified:
   projects/aop/trunk/aop/
   projects/aop/trunk/aop/build-tests-jdk50.xml
   projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
Log:
[JBAOP-424] Fix NPEs with PER_INSTANCE lightwight aspects. Still need more tests


Property changes on: projects/aop/trunk/aop
___________________________________________________________________
Name: svn:ignore
   - output
build.log
TEST-org.jboss.test.aop.*.txt
junit*.properties
comments.txt
jbossAgent.dll
jboss-aop-dist.zip
local.properties
org
*.class
aopc.tmpdir
target

   + output
build.log
TEST-org.jboss.test.aop.*.txt
junit*.properties
comments.txt
jbossAgent.dll
jboss-aop-dist.zip
local.properties
org
*.class
aopc.tmpdir
target
com


Modified: projects/aop/trunk/aop/build-tests-jdk50.xml
===================================================================
--- projects/aop/trunk/aop/build-tests-jdk50.xml	2007-06-19 21:58:02 UTC (rev 63574)
+++ projects/aop/trunk/aop/build-tests-jdk50.xml	2007-06-19 22:06:38 UTC (rev 63575)
@@ -405,6 +405,10 @@
          <param name="test" value="beforeafterthrowingstack"/>
          <param name="caller" value="javaagent-genadvisor-tests"/>
       </antcall>
+      <antcall target="_run-javaagent-test" inheritRefs="true">
+         <param name="test" value="beforeafterthrowingscoped"/>
+         <param name="caller" value="javaagent-genadvisor-tests"/>
+      </antcall>
 
       <!-- Add tests in _base-tests unless they should only be run in this weaving mode -->
       <antcall target="_base-jdk50-tests" inheritRefs="true">
@@ -584,6 +588,10 @@
          <param name="test" value="beforeafterthrowingstack"/>
          <param name="caller" value="precompiled-genadvisor-tests"/>
       </antcall>
+      <antcall target="_run-precompiled-test" inheritRefs="true">
+         <param name="test" value="beforeafterthrowingscoped"/>
+         <param name="caller" value="precompiled-genadvisor-tests"/>
+      </antcall>
       
        <!-- This should only be run using compile-time weaving -->
       <antcall target="_run-precompiled-test" inheritRefs="true">

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2007-06-19 21:58:02 UTC (rev 63574)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2007-06-19 22:06:38 UTC (rev 63575)
@@ -166,7 +166,6 @@
    {
       ConByConInfo copy = (ConByConInfo)info.copy();
       copy.setAdvisor(this);
-//      addMethodInfo(copy);
       return copy;
    }
 
@@ -177,7 +176,6 @@
    {
       MethodByConInfo copy = (MethodByConInfo)info.copy();
       copy.setAdvisor(this);
-//      addMethodInfo(copy);
       return copy;
    }
 
@@ -188,7 +186,6 @@
    {
       ConByMethodInfo copy = (ConByMethodInfo)info.copy();
       copy.setAdvisor(this);
-//      addMethodInfo(copy);
       return copy;
    }
    
@@ -199,7 +196,6 @@
    {
       MethodByMethodInfo copy = (MethodByMethodInfo)info.copy();
       copy.setAdvisor(this);
-//      addMethodInfo(copy);
       return copy;
    }
    
@@ -1024,14 +1020,24 @@
       generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
    }
    
-   protected void rebindJoinPointWithInstanceInformation(JoinPointInfo info)
+   protected Object rebindJoinPointWithInstanceInformation(JoinPointInfo info)
    {
       JoinPointGenerator generator = getJoinPointGenerator(info);
       generator.rebindJoinpoint(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      return generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
    }
    
    /**
+    * Called back from generated code
+    */
+   public Object createAndRebindJoinPointForInstance(JoinPointInfo info)
+   {
+      JoinPointInfo newinfo = info.copy();
+      newinfo.setAdvisor(this);
+      return rebindJoinPointWithInstanceInformation(newinfo);
+   }
+   
+   /**
     * Encapsulates different behaviours depending on if this is an instance or class advisor
     */
    private interface AdvisorStrategy

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java	2007-06-19 21:58:02 UTC (rev 63574)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java	2007-06-19 22:06:38 UTC (rev 63575)
@@ -60,6 +60,7 @@
    protected JoinPointInfo(JoinPointInfo other)
    {
       this.advisor = other.advisor;
+      this.clazz = other.clazz;
       if (other.interceptors != null)
       {
          this.interceptors = new Interceptor[other.interceptors.length];

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java	2007-06-19 21:58:02 UTC (rev 63574)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java	2007-06-19 22:06:38 UTC (rev 63575)
@@ -262,7 +262,7 @@
 
       CtClass[] params = addTargetToParamsForNonStaticMethod(trans.getClazz(), trans.getWMethod());
 
-      String code = createAdvisorMethodBody(trans, genadvisor/*kill*/);
+      String code = createAdvisorMethodBody(trans);
       try
       {
          CtMethod advisorMethod = CtNewMethod.make(
@@ -283,7 +283,7 @@
       }
    }
 
-   private String createAdvisorMethodBody(MethodTransformation trans, CtClass ga/*kill*/)throws NotFoundException
+   private String createAdvisorMethodBody(MethodTransformation trans)throws NotFoundException
    {
       if (Modifier.isStatic(trans.getWMethod().getModifiers()))
       {
@@ -291,7 +291,7 @@
       }
       else
       {
-         return createNonStaticAdvisorMethodBody(trans, ga);
+         return createNonStaticAdvisorMethodBody(trans);
       }
    }
 
@@ -319,7 +319,7 @@
       return code;
    }
 
-   private String createNonStaticAdvisorMethodBody(MethodTransformation trans, CtClass ga/*kill*/)throws NotFoundException
+   private String createNonStaticAdvisorMethodBody(MethodTransformation trans)throws NotFoundException
    {
       String joinpointName = getJoinPointFieldName(trans);
       String infoName = getMethodInfoFieldName(trans.getOriginalName(), trans.getHash());

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java	2007-06-19 21:58:02 UTC (rev 63574)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java	2007-06-19 22:06:38 UTC (rev 63575)
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javassist.CannotCompileException;
@@ -43,11 +44,13 @@
 import javassist.Modifier;
 import javassist.NotFoundException;
 
+import org.jboss.aop.Advisor;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.CallerConstructorInfo;
 import org.jboss.aop.GeneratedClassAdvisor;
 import org.jboss.aop.InstanceAdvisor;
 import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.MethodInfo;
 import org.jboss.aop.advice.AdviceMethodProperties;
 import org.jboss.aop.advice.AdviceType;
 import org.jboss.aop.advice.GeneratedAdvisorInterceptor;
@@ -73,6 +76,9 @@
    private static final Logger logger = AOPLogger.getLogger(JoinPointGenerator.class);
    
    public static final String INFO_FIELD = "info";
+   public static final String INITIALISED_LIGHTWEIGHT_INSTANCE_ASPECTS = "initialisedLightweightInstanceAspects";
+   public static final String INITIALISE_LIGHTWEIGHT_INSTANCE_ASPECTS = "initialisePerInstanceAspects";
+   public static final String IS_FOR_INSTANCE_ADVISOR = "isForInstanceAdvisor";
    public static final String INVOKE_JOINPOINT = "invokeJoinpoint";
    public static final String INVOKE_TARGET = "invokeTarget";
    public static final String DISPATCH = "dispatch";
@@ -219,7 +225,7 @@
    /**
     * Called by the joinpoint if a interceptors were regenereated
     */
-   public synchronized void generateJoinPointClass(ClassLoader classloader, JoinPointInfo info)
+   public synchronized Object generateJoinPointClass(ClassLoader classloader, JoinPointInfo info)
    {
       if (info == null)
       {
@@ -228,11 +234,11 @@
       
       if (System.getSecurityManager() == null)
       {
-         GenerateJoinPointClassAction.NON_PRIVILEGED.generateJoinPointClass(classloader, this, info);
+         return GenerateJoinPointClassAction.NON_PRIVILEGED.generateJoinPointClass(classloader, this, info);
       }
       else
       {
-         GenerateJoinPointClassAction.PRIVILEGED.generateJoinPointClass(classloader, this, info);
+         return GenerateJoinPointClassAction.PRIVILEGED.generateJoinPointClass(classloader, this, info);
       }
    }
     
@@ -240,7 +246,7 @@
     * Does the work for generateJoinPointClass()
     * @see JoinPointGenerator#generateJoinPointClass()
     */
-   private void doGenerateJoinPointClass(ClassLoader classloader, JoinPointInfo info)
+   private Object doGenerateJoinPointClass(ClassLoader classloader, JoinPointInfo info)
    {
       try
       {
@@ -272,15 +278,21 @@
          Object obj = instantiateClass(clazz, generatedClass.getAroundSetups(), info);
          
          joinpointField.set(info.getAdvisor(), obj);
+         if (info.getAdvisor() instanceof InstanceAdvisor)
+         {
+            Field field = clazz.getDeclaredField(IS_FOR_INSTANCE_ADVISOR);
+            SecurityActions.setAccessible(field);
+            field.set(obj, Boolean.TRUE);
+         }
+         initialised = true;
+         return obj;
       }
       catch (Throwable e)
       {
          e.printStackTrace();
          // AutoGenerated
          throw new RuntimeException("Error generating joinpoint class for joinpoint " + info, e);
-         
       }
-      initialised = true;
    }
 
    private Class toClass(ClassPool pool, CtClass ctclass, ProtectionDomain pd) throws NotFoundException, CannotCompileException, ClassNotFoundException
@@ -290,6 +302,7 @@
    
    private Object instantiateClass(Class clazz, AdviceSetup[] aroundSetups, JoinPointInfo info) throws Exception
    {
+//      System.out.println("Creating instance of " + clazz + " for advisor " + info.getAdvisor().getClass().getName());
       Constructor ctor = clazz.getConstructor(new Class[] {info.getClass()});
       Object obj;
       try
@@ -352,6 +365,7 @@
          addUntransformableInterface(pool, clazz);
   
          AdviceSetups setups = initialiseAdviceInfosAndAddFields(pool, clazz, newInfo);
+         createInitialisePerInstanceAspectsMethod(clazz, setups, newInfo.getClazz());
          
          createConstructors(pool, superClass, clazz, setups);
          createJoinPointInvokeMethod(
@@ -388,6 +402,38 @@
       return baseJoinPointClassName + getIncrement();
    }
 
+   private void createInitialisePerInstanceAspectsMethod(CtClass clazz, AdviceSetups setups, Class advisedClass) throws CannotCompileException, NotFoundException
+   {
+      if (setups.hasLightweightAdvicesRequiringInstanceAdvisor())
+      {
+         StringBuffer code = new StringBuffer("{");
+         for (AdviceSetup setup : setups.getLightweightAdvicesRequiringInstanceAdvisor())
+         {
+            AdviceType type = setup.getType();
+            if (type != AdviceType.AROUND && setup.requiresInstanceAdvisor())
+            {
+               code.append(getPerInstanceAspectCode("$1", setup, false));
+            }
+            
+         }
+         code.append("}");
+
+         String name = advisedClass.getName();
+         CtClass ctTarget = clazz.getClassPool().get(name);
+         
+         CtMethod method = CtNewMethod.make(
+               Modifier.PRIVATE, 
+               CtClass.voidType,
+               INITIALISE_LIGHTWEIGHT_INSTANCE_ASPECTS,
+               new CtClass[] {ctTarget},//target
+               EMPTY_CTCLASS_ARRAY,
+               code.toString(),
+               clazz);
+         clazz.addMethod(method);
+         
+      }
+   }
+   
    protected abstract boolean isVoid();
    protected abstract Class getReturnType(); 
    protected abstract AdviceMethodProperties getAdviceMethodProperties(JoinPointBean info, AdviceSetup setup);
@@ -461,7 +507,7 @@
          addAspectFieldAndGetter(pool, clazz, setups[i]);
          addCFlowFieldsAndGetters(pool, setups[i], clazz, cflows);
       }
-   
+      addLightweightInstanceAspectsTrackerFields(clazz);
       return new AdviceSetups(info, setups);
    }
    
@@ -494,17 +540,9 @@
    {
       if (setup.requiresInstanceAdvisor())
       {
-         String instanceAdvisor = (isCaller()) ?
-               "org.jboss.aop.InstanceAdvisor ia = ((org.jboss.aop.Advised)callingObject)._getInstanceAdvisor();" :
-                  "org.jboss.aop.InstanceAdvisor ia = ((org.jboss.aop.Advised)targetObject)._getInstanceAdvisor();";
+         String instanceAdvisor = (isCaller()) ? "callingObject" : "targetObject";
                         
-         return
-            "{" +
-            "   " + instanceAdvisor +
-            "   org.jboss.aop.advice.GeneratedAdvisorInterceptor fw = (org.jboss.aop.advice.GeneratedAdvisorInterceptor)info.getInterceptors()[" + setup.getIndex() + "];" +
-            "   Object o = fw.getPerInstanceAspect(info.getAdvisor(), info.getJoinpoint(), ia);" +
-            "   return (" + setup.getAspectClass().getName() + ")o;" +
-            "}";
+         return getPerInstanceAspectCode(instanceAdvisor, setup, true);
       }
       else
       {
@@ -520,6 +558,20 @@
             "}";
       }
    }
+   
+   private String getPerInstanceAspectCode(String objectWithInstanceAdvisor, AdviceSetup setup, boolean shouldReturn)
+   {
+      String instanceAdvisor = "org.jboss.aop.InstanceAdvisor ia = ((org.jboss.aop.Advised)" + objectWithInstanceAdvisor + ")._getInstanceAdvisor();";
+      String assignOrReturn = (shouldReturn) ? "return " : setup.getAspectFieldName() + " = ";
+      return
+      "{" +
+      "   " + instanceAdvisor +
+      "   org.jboss.aop.advice.GeneratedAdvisorInterceptor fw = (org.jboss.aop.advice.GeneratedAdvisorInterceptor)info.getInterceptors()[" + setup.getIndex() + "];" +
+      "   Object o = fw.getPerInstanceAspect(info.getAdvisor(), info.getJoinpoint(), ia);" +
+      "   " + assignOrReturn + "(" + setup.getAspectClass().getName() + ")o;" +
+      "}";
+   }
+   
    private void addCFlowFieldsAndGetters(ClassPool pool, AdviceSetup setup,
          CtClass clazz, HashMap<String, Integer> cflows)
          throws NotFoundException, CannotCompileException
@@ -562,6 +614,15 @@
       }
    }
    
+   private void addLightweightInstanceAspectsTrackerFields(CtClass clazz) throws CannotCompileException
+   {
+      CtField initialised = new CtField(CtClass.booleanType, INITIALISED_LIGHTWEIGHT_INSTANCE_ASPECTS, clazz);
+      clazz.addField(initialised);
+      
+      CtField forInstance = new CtField(CtClass.booleanType, IS_FOR_INSTANCE_ADVISOR, clazz);
+      clazz.addField(forInstance);
+   }
+   
    private void createJoinPointInvokeMethod(CtClass superClass, CtClass clazz, boolean isVoid, AdviceSetups setups, JoinPointInfo info) throws CannotCompileException, NotFoundException
    {
       CtMethod superInvoke = superClass.getDeclaredMethod(INVOKE_JOINPOINT);
@@ -569,6 +630,7 @@
       try
       {
          code = createJoinpointInvokeBody(
+               superClass,
                clazz, 
                setups,
                superInvoke.getExceptionTypes(), superInvoke.getParameterTypes(), info);
@@ -587,7 +649,7 @@
       }
    }
    
-   private String createJoinpointInvokeBody(CtClass joinpointClass,
+   private String createJoinpointInvokeBody(CtClass joinpointSuperClass, CtClass joinpointClass,
          AdviceSetups setups, CtClass[] declaredExceptions, CtClass[] parameterTypes, JoinPointInfo info)throws NotFoundException
    {
       AdviceCallStrategy defaultCall = DefaultAdviceCallStrategy.getInstance();
@@ -618,8 +680,11 @@
       code.append("Throwable ").append(THROWABLE).append(" = null;");
       
       
+      addInitialiseLightweightPerInstanceAdvicesCode(joinpointSuperClass, info, code, setups);
+
       code.append("   try");
       code.append("   {");
+//      code.append("System.out.println(\"invokeJP - \" + java.lang.System.identityHashCode(this));");
       boolean argsFoundBefore = defaultCall.
          addInvokeCode(this, setups.getByType(AdviceType.BEFORE), code, info);
       
@@ -672,16 +737,55 @@
       {
          code.append("   return " + RETURN_VALUE + ";");
       }
+
       code.append("}");
-      
+
       // declare arguments array if necessary
       if (argsFoundBefore || argsFoundAfter)
       {
          code.insert(1, parameters.declareArgsArray(parameterTypes.length, nullArgsArray));
       }
+
       return code.toString();
    }
 
+   private void addInitialiseLightweightPerInstanceAdvicesCode(CtClass joinpointSuperClass, JoinPointInfo info, StringBuffer code, AdviceSetups setups)
+   {
+      if (setups.hasLightweightAdvicesRequiringInstanceAdvisor())
+      {
+         if (!hasCallingObject() && !hasTargetObject())
+         {
+            //Without either a calling object or a target object we can not create an instance advisor
+            return;
+         }
+
+         //caller should always come before the target in the list for invokeJoinPoint(), if using
+         //a caller pointcut the instanceadvisor is the caller's, so it should be a safe assumption 
+         //to always use $1
+         String instanceAdvisor = "$1";
+         
+         code.append("if (!" + INITIALISED_LIGHTWEIGHT_INSTANCE_ASPECTS + "){");
+         code.append("   if(" + IS_FOR_INSTANCE_ADVISOR + "){");
+         code.append("      " + INITIALISE_LIGHTWEIGHT_INSTANCE_ASPECTS + "(" + instanceAdvisor + ");");
+         code.append(INITIALISED_LIGHTWEIGHT_INSTANCE_ASPECTS + " = true;");
+         code.append("   }else{");
+         code.append("      org.jboss.aop.GeneratedClassAdvisor instanceAdvisor = (org.jboss.aop.GeneratedClassAdvisor)((org.jboss.aop.Advised)" + instanceAdvisor + ")._getInstanceAdvisor();");
+         code.append("      Object objJp = instanceAdvisor.createAndRebindJoinPointForInstance((org.jboss.aop.JoinPointInfo)super.info);");//Needs to be info for the instance advisor, convert?
+         code.append("      " + joinpointSuperClass.getName() + " jp = (" + joinpointSuperClass.getName() + ")objJp;");
+         if (isVoid())
+         {
+            code.append("      jp." + INVOKE_JOINPOINT + "($$);");
+            code.append("return;");
+         }
+         else
+         {
+            code.append("      return jp." + INVOKE_JOINPOINT + "($$);");
+         }
+         code.append("   }");
+         code.append("}");
+      }
+   }
+   
    private boolean addAroundInvokeCode(StringBuffer code, AdviceSetups setups,
          CtClass joinpointClass, boolean argsFoundBefore, CtClass[] parameterTypes)
    throws NotFoundException
@@ -1361,6 +1465,8 @@
    {
       AdviceSetup[] allSetups;
       AdviceSetup[][] setups;
+      List<AdviceSetup> lightweightAdvicesRequiringInstanceAdvisor;
+      boolean hasAroundAdvices;
       
       AdviceSetups(JoinPointInfo info, AdviceSetup[] allSetups)
       {
@@ -1369,7 +1475,6 @@
          ArrayList<AdviceSetup>[] aspects = (ArrayList<AdviceSetup>[]) new ArrayList<?>[length];
          for (int i = 0 ; i < allSetups.length ; i++)
          {
-            
             AdviceMethodProperties properties = getAdviceMethodProperties(info, allSetups[i]);
             AdviceType type = allSetups[i].getType();
             int index = type.ordinal();
@@ -1383,6 +1488,20 @@
             {
                allSetups[i].setAdviceMethodProperties(properties);
                aspects[index].add(allSetups[i]);
+               
+               if (AdviceType.AROUND == type)
+               {
+                  hasAroundAdvices = true;
+               }
+               else if (allSetups[i].requiresInstanceAdvisor())
+               {
+                  //We are not an around advice and we require an instance advisor
+                  if (lightweightAdvicesRequiringInstanceAdvisor == null)
+                  {
+                     lightweightAdvicesRequiringInstanceAdvisor = new ArrayList<AdviceSetup>();
+                  }
+                  lightweightAdvicesRequiringInstanceAdvisor.add(allSetups[i]);
+               }
             }
             else if (AspectManager.verbose)
             {
@@ -1419,24 +1538,33 @@
       {
          return this.setups[type.ordinal()];
       }
+
+      public boolean hasLightweightAdvicesRequiringInstanceAdvisor()
+      {
+         return lightweightAdvicesRequiringInstanceAdvisor != null && lightweightAdvicesRequiringInstanceAdvisor.size() > 0;  
+      }
+      
+      public List<AdviceSetup> getLightweightAdvicesRequiringInstanceAdvisor()
+      {
+         return lightweightAdvicesRequiringInstanceAdvisor;
+      }
    }
 
    private interface GenerateJoinPointClassAction
    {
-      void generateJoinPointClass(ClassLoader classloader, JoinPointGenerator joinPointGenerator, JoinPointInfo info);
+      Object generateJoinPointClass(ClassLoader classloader, JoinPointGenerator joinPointGenerator, JoinPointInfo info);
       
       GenerateJoinPointClassAction PRIVILEGED = new GenerateJoinPointClassAction()
       {
-         public void generateJoinPointClass(final ClassLoader classloader, final JoinPointGenerator joinPointGenerator, final JoinPointInfo info) 
+         public Object generateJoinPointClass(final ClassLoader classloader, final JoinPointGenerator joinPointGenerator, final JoinPointInfo info) 
          {
             try
             {
-               AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
                {
                   public Object run() throws Exception
                   {
-                     joinPointGenerator.doGenerateJoinPointClass(classloader, info);
-                     return null;
+                     return joinPointGenerator.doGenerateJoinPointClass(classloader, info);
                   }
                });
             }
@@ -1454,9 +1582,9 @@
 
       GenerateJoinPointClassAction NON_PRIVILEGED = new GenerateJoinPointClassAction()
       {
-         public void generateJoinPointClass(ClassLoader classloader, JoinPointGenerator joinPointGenerator, JoinPointInfo info)
+         public Object generateJoinPointClass(ClassLoader classloader, JoinPointGenerator joinPointGenerator, JoinPointInfo info)
          {
-            joinPointGenerator.doGenerateJoinPointClass(classloader, info);
+            return joinPointGenerator.doGenerateJoinPointClass(classloader, info);
          }
       };
    }

Added: projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml	                        (rev 0)
+++ projects/aop/trunk/aop/src/resources/test/beforeafterthrowingscoped/jboss-aop.xml	2007-06-19 22:06:38 UTC (rev 63575)
@@ -0,0 +1,10 @@
+<aop>
+	<aspect class="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" scope="PER_INSTANCE"/>
+	
+	<bind pointcut="execution(* org.jboss.test.aop.beforeafterthrowingscoped.POJO->methodWithPerInstanceAspects(..))">
+		<before aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="before"/>
+		<after aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="after"/>
+		<throwing aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="throwing"/>		
+		<finally aspect="org.jboss.test.aop.beforeafterthrowingscoped.PerInstanceAspect" name="finaly"/>
+	</bind>
+</aop>
\ No newline at end of file

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/BeforeAfterThrowingScopedTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/BeforeAfterThrowingScopedTestCase.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/BeforeAfterThrowingScopedTestCase.java	2007-06-19 22:06:38 UTC (rev 63575)
@@ -0,0 +1,115 @@
+/*
+* 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.test.aop.beforeafterthrowingscoped;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.aop.AOPTestWithSetup;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeforeAfterThrowingScopedTestCase extends AOPTestWithSetup
+{
+   public BeforeAfterThrowingScopedTestCase(String arg0)
+   {
+      super(arg0);
+   }
+
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("BeforeAfterThrowingScopedTestCase");
+      suite.addTestSuite(BeforeAfterThrowingScopedTestCase.class);
+      return suite;
+   }
+
+   public void testPerInstanceAspects()
+   {
+      System.out.println("===== testPerInstanceAspects()");
+      System.out.println("Calling POJO 1");
+      PerInstanceAspect.reset();
+      POJO pojo1 = new POJO();
+      try
+      {
+         pojo1.methodWithPerInstanceAspects(false);
+      }
+      catch (ThrownByTestException e)
+      {
+         fail("Did not expect excpeption here");
+      }
+    
+      assertNotNull(PerInstanceAspect.before);
+      assertNotNull(PerInstanceAspect.after);
+      assertNull(PerInstanceAspect.throwing);
+      assertNotNull(PerInstanceAspect.finaly);
+      assertSame(PerInstanceAspect.before, PerInstanceAspect.after);
+      assertSame(PerInstanceAspect.after, PerInstanceAspect.finaly);
+      PerInstanceAspect aspect1 = PerInstanceAspect.before;
+      
+      System.out.println("Calling POJO 2");
+      PerInstanceAspect.reset();
+      POJO pojo2 = new POJO();
+      try
+      {
+         pojo2.methodWithPerInstanceAspects(true);
+         fail("Should have thrown an exception");
+      }
+      catch (ThrownByTestException expected)
+      {
+      }
+      
+      assertNotNull(PerInstanceAspect.before);
+      assertNull(PerInstanceAspect.after);
+      assertNotNull(PerInstanceAspect.throwing);
+      assertNotNull(PerInstanceAspect.finaly);
+      assertSame(PerInstanceAspect.before, PerInstanceAspect.throwing);
+      assertSame(PerInstanceAspect.throwing, PerInstanceAspect.finaly);
+      PerInstanceAspect aspect2 = PerInstanceAspect.before;
+    
+      assertNotSame(aspect1, aspect2);
+      
+      
+      System.out.println("Calling POJO 1 again");
+      try
+      {
+         pojo1.methodWithPerInstanceAspects(false);
+      }
+      catch (ThrownByTestException e)
+      {
+         fail("Did not expect excpeption here");
+      }
+    
+      PerInstanceAspect aspect1a = PerInstanceAspect.before;
+      
+      assertSame(aspect1, aspect1a);
+      System.out.println("DONE");
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJO.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/POJO.java	2007-06-19 22:06:38 UTC (rev 63575)
@@ -0,0 +1,39 @@
+/*
+* 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.test.aop.beforeafterthrowingscoped;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class POJO
+{
+   public void methodWithPerInstanceAspects(boolean error) throws ThrownByTestException
+   {
+      if (error)
+      {
+         throw new ThrownByTestException();
+      }
+   }
+   
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/PerInstanceAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/PerInstanceAspect.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/PerInstanceAspect.java	2007-06-19 22:06:38 UTC (rev 63575)
@@ -0,0 +1,66 @@
+/*
+* 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.test.aop.beforeafterthrowingscoped;
+
+import org.jboss.aop.advice.annotation.Thrown;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstanceAspect
+{
+   public static PerInstanceAspect before;
+   public static PerInstanceAspect after;
+   public static PerInstanceAspect throwing;
+   public static PerInstanceAspect finaly;
+   
+   public void before()
+   {
+      before = this;
+   }
+   
+   public void after()
+   {
+      after = this;
+   }
+   
+   public void throwing(@Thrown Throwable e)
+   {
+      throwing = this;
+   }
+   
+   public void finaly()
+   {
+      finaly = this;
+   }
+   
+   public static void reset()
+   {
+      before = null;
+      after = null;
+      throwing = null;
+      finaly = null;
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/ThrownByTestException.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/ThrownByTestException.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingscoped/ThrownByTestException.java	2007-06-19 22:06:38 UTC (rev 63575)
@@ -0,0 +1,32 @@
+/*
+* 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.test.aop.beforeafterthrowingscoped;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ThrownByTestException extends Exception
+{
+
+}




More information about the jboss-cvs-commits mailing list