]> source.dussan.org Git - aspectj.git/commitdiff
Test and fix for Bugzilla Bug 50570
authorjhugunin <jhugunin>
Wed, 28 Jan 2004 01:12:17 +0000 (01:12 +0000)
committerjhugunin <jhugunin>
Wed, 28 Jan 2004 01:12:17 +0000 (01:12 +0000)
   CatchClauseSignature has broken operation

tests/ajcTests.xml
tests/bugs/HandlerSig.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/Member.java
weaver/src/org/aspectj/weaver/ResolvedMember.java
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java

index 8d17bd6fe35de500feef04ac15be9818ff1add26..e9ade4e18d7de5657da5ea301213cfed62ed3dc6 100644 (file)
         <run class="SubtypeConstructorCW"/>
     </ajc-test>
         
+    <ajc-test dir="bugs" pr="50570"
+      title="CatchClauseSignature has broken operation">
+        <compile files="HandlerSig.java"/>
+        <run class="HandlerSig"/>
+    </ajc-test>
 </suite>
diff --git a/tests/bugs/HandlerSig.java b/tests/bugs/HandlerSig.java
new file mode 100644 (file)
index 0000000..8e64481
--- /dev/null
@@ -0,0 +1,42 @@
+import org.aspectj.testing.Tester;
+
+import org.aspectj.lang.reflect.*;
+
+public class HandlerSig {
+
+       public void doSomething() {
+               // Get around "unreachable code error...
+               if (true)
+               {
+                       throw new BusinessException("Surprise!!");
+               }
+               System.out.println("Busy doing something.");
+       }
+
+       public static void main(String[] args) {
+               try {
+                       HandlerSig m = new HandlerSig();
+                       m.doSomething();
+               } catch (BusinessException be) {
+                       Tester.checkEqual(be.getMessage(), "Surprise!!");
+               }
+       }
+}
+
+class BusinessException extends RuntimeException {
+       BusinessException(String message) {
+               super(message);
+       }
+}
+
+aspect AppMonitor {
+       pointcut problemHandling() : handler(Throwable+);
+
+       before() : problemHandling() {
+               CatchClauseSignature cSig =
+                       (CatchClauseSignature) thisJoinPointStaticPart.getSignature();
+
+               Tester.checkEqual(cSig.getParameterType(), BusinessException.class);
+               Tester.checkEqual(cSig.getParameterName(), "be");
+       }
+}
index 79cfbadfc9b34407a9172ad9ceae3730187a35f3..d30a60f8e5d3811518184ba9034127e6a469ded7 100644 (file)
@@ -190,8 +190,8 @@ public class Member implements Comparable {
             paramTys);
     }
     
-       public static Member makeExceptionHandlerSignature(TypeX inType, TypeX catchType) {
-               return new Member(
+       public static ResolvedMember makeExceptionHandlerSignature(TypeX inType, TypeX catchType) {
+               return new ResolvedMember(
                        HANDLER,
                        inType,
                        Modifier.STATIC,
@@ -596,11 +596,9 @@ public class Member implements Comparable {
         buf.append('-');
         buf.append(makeString(getParameterTypes()[0]));
         buf.append('-');
-        //XXX we don't actually try to find the handler parameter name
-        //XXX it probably wouldn't be too hard
         String pName = "<missing>";
-        //String[] pNames = getParameterNames(world);
-        //if (pNames != null) pName = pNames[0];
+        String[] names = getParameterNames(world);
+        if (names != null) pName = names[0];
         buf.append(pName);
         buf.append('-');
         return buf.toString();
index d1a4e9633a7c527601c47eced020dd2cf57bec3c..ab1cdc90f2b7e03a8e24d8367376591fbc8b29a0 100644 (file)
@@ -26,7 +26,7 @@ import org.aspectj.bridge.ISourceLocation;
  */
 public class ResolvedMember extends Member implements IHasPosition {
     
-    protected String[] parameterNames = null;
+    public String[] parameterNames = null;
     protected TypeX[] checkedExceptions = TypeX.NONE;
     
     
index fd72970cd745c9cf4009725c15a78a62cbcec43b..c4ce575bb6dcb37a5e3fc0aa6fef21474d65145d 100644 (file)
@@ -40,6 +40,7 @@ import org.apache.bcel.generic.NEW;
 import org.apache.bcel.generic.ObjectType;
 import org.apache.bcel.generic.ReturnInstruction;
 import org.apache.bcel.generic.SWAP;
+import org.apache.bcel.generic.StoreInstruction;
 import org.apache.bcel.generic.TargetLostException;
 import org.apache.bcel.generic.Type;
 import org.aspectj.bridge.ISourceLocation;
@@ -408,11 +409,16 @@ public class BcelShadow extends Shadow {
                InstructionList body = enclosingMethod.getBody();
                TypeX catchType = exceptionRange.getCatchType();
                TypeX inType = enclosingMethod.getEnclosingClass().getType();
+               
+               ResolvedMember sig = Member.makeExceptionHandlerSignature(inType, catchType);
+               
+                       
+               sig.parameterNames = new String[] {findHandlerParamName(startOfHandler)};
         BcelShadow s =
             new BcelShadow(
                 world,
                 ExceptionHandler,
-                Member.makeExceptionHandlerSignature(inType, catchType),
+                sig,
                 enclosingMethod,
                 enclosingShadow);
         ShadowRange r = new ShadowRange(body);
@@ -424,6 +430,27 @@ public class BcelShadow extends Shadow {
         exceptionRange.updateTarget(startOfHandler, start, body);
         return s;
        }
+       
+       private static String findHandlerParamName(InstructionHandle startOfHandler) {          
+               if (startOfHandler.getInstruction() instanceof StoreInstruction &&
+                       startOfHandler.getNext() != null)
+               {
+                       int slot = ((StoreInstruction)startOfHandler.getInstruction()).getIndex();
+                       //System.out.println("got store: " + startOfHandler.getInstruction() + ", " + index);
+                       InstructionTargeter[] targeters = startOfHandler.getNext().getTargeters();
+                       for (int i=targeters.length-1; i >= 0; i--) {
+                               if (targeters[i] instanceof LocalVariableTag) {
+                                       LocalVariableTag t = (LocalVariableTag)targeters[i];
+                                       if (t.getSlot() == slot) {
+                                               return t.getName();
+                                       }
+                                       //System.out.println("tag: " + targeters[i]);
+                               }
+                       }
+               }
+               
+               return "<missing>";
+       }
     
     /** create an init join point associated w/ an interface in the body of a constructor */