]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 119749
authoraclement <aclement>
Tue, 13 Dec 2005 13:41:47 +0000 (13:41 +0000)
committeraclement <aclement>
Tue, 13 Dec 2005 13:41:47 +0000 (13:41 +0000)
tests/bugs150/pr119749/InheritedThrows.java
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/Advice.java
weaver/src/org/aspectj/weaver/ResolvedType.java

index d29a7208956380a5f16921a3b51dd77eb8c106a9..3c3021d5d39cd212d11699552fe612154281deb9 100644 (file)
@@ -1,10 +1,7 @@
 public class InheritedThrows {
 
     static aspect A {
-        declare warning : execution (* *.*(..) throws Ex1) : "one";
-//        declare warning : execution (* *.*(..) throws Ex2) : "two";
-//        declare warning : execution (* *.*(..) throws !(Ex1||Ex2)) : "neither";
-//        declare warning : execution (* *.*(..) throws Ex1, Ex2) : "both";
+        after() throwing(Ex1 a): execution(* *.*(..) throws Ex1) {}
     }
 
     public static class Ex1 extends Exception {}
@@ -16,7 +13,7 @@ public class InheritedThrows {
     }
 
     private static class NestedClass1 implements MyInterface {
-        public void m() throws Ex1 {}
+        public void m() throws Ex1 {} // MATCHES HERE
     }
 
     private static class NestedClass2 implements MyInterface {
@@ -24,7 +21,7 @@ public class InheritedThrows {
     }
 
     private static class NestedClassBoth implements MyInterface {
-        public void m() throws Ex1, Ex2 {}
+        public void m() throws Ex1, Ex2 {}  // MATCHES HERE
     }
 
     private static class NestedClassNeither implements MyInterface {
index 1ff229944be8bbb0dff3ac92bf706f0a939bc591..ba040ceac6a81c5331b1da10591f5900dba063cc 100644 (file)
@@ -52,7 +52,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testCunningDeclareParents_pr92311() { runTest("cunning declare parents");}
   public void testGenericITDsAndAbstractMethodError_pr102357() { runTest("generic itds and abstract method error");}
   */
-  //public void testIncorrectSignatureMatchingWithExceptions_pr119749() { runTest("incorrect exception signature matching");}
+  public void testIncorrectSignatureMatchingWithExceptions_pr119749() { runTest("incorrect exception signature matching");}
   public void testGeneratingCodeForAnOldRuntime_pr116679_1() { runTest("generating code for a 1.2.1 runtime - 1");}
   public void testGeneratingCodeForAnOldRuntime_pr116679_2() { runTest("generating code for a 1.2.1 runtime - 2");}
   public void testAmbiguousMethod_pr118599_1() { runTest("ambiguous method when binary weaving - 1");}
index 790dca6f97e845c9b6ece86b0a9e8a17d9bb2982..a73365dc27928396fcd5ceda5ff31578fa4caeca 100644 (file)
     </ajc-test>  
     
     <ajc-test dir="bugs150/pr119749" pr="119749" title="incorrect exception signature matching">
-     <compile files="InheritedThrows.java" options="">  
-       <message kind="warning" line="19" text="one"/>
-       <message kind="warning" line="27" text="one"/>
+     <compile files="InheritedThrows.java" options="-showWeaveInfo">  
+       <message kind="weave" text="Join point 'method-execution(void InheritedThrows$NestedClassBoth.m())' in Type 'InheritedThrows$NestedClassBoth' (InheritedThrows.java:24) advised by afterThrowing advice from 'InheritedThrows$A' (InheritedThrows.java:4)"/>
+       <message kind="weave" text="Join point 'method-execution(void InheritedThrows$NestedClass1.m())' in Type 'InheritedThrows$NestedClass1' (InheritedThrows.java:16) advised by afterThrowing advice from 'InheritedThrows$A' (InheritedThrows.java:4)"/>
      </compile>
     </ajc-test>  
     
index 791b9a853390b58c61b64a5e85f944c126c7cbf7..f8b26a41e643f51ebd6cbd3fd0a4842ba0ee5682 100644 (file)
@@ -116,8 +116,8 @@ public abstract class Advice extends ShadowMunger {
                                }
                        }
                        
-                       
-               if (hasExtraParameter() && kind == AdviceKind.AfterReturning) {
+
+                       if (hasExtraParameter() && kind == AdviceKind.AfterReturning) {
                        ResolvedType resolvedExtraParameterType = getExtraParameterType().resolve(world);
                        ResolvedType shadowReturnType = shadow.getReturnType().resolve(world);
                        boolean matches = 
@@ -127,6 +127,16 @@ public abstract class Advice extends ShadowMunger {
                                maybeIssueUncheckedMatchWarning(resolvedExtraParameterType,shadowReturnType,shadow,world);
                        }
                        return matches;
+                       } else if (hasExtraParameter() && kind==AdviceKind.AfterThrowing) { // pr119749
+                               ResolvedType exceptionType = getExtraParameterType().resolve(world);
+                               if (!exceptionType.isCheckedException()) return true;
+                               UnresolvedType[] shadowThrows = shadow.getSignature().getExceptions(world);
+                               boolean matches = false;
+                               for (int i = 0; i < shadowThrows.length && !matches; i++) {
+                                               ResolvedType type = shadowThrows[i].resolve(world);
+                                               if (exceptionType.isAssignableFrom(type)) matches=true;
+                                       }
+                               return matches;
                } else if (kind == AdviceKind.PerTargetEntry) {
                        return shadow.hasTarget();
                } else if (kind == AdviceKind.PerThisEntry) {
index d16b041c241479b395d4ad0e1567abc01f244fa2..ee8b7d0ac8f7d945d0251ee1d0c35f3cc70ec6ed 100644 (file)
@@ -1883,6 +1883,22 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
        public ResolvedPointcutDefinition findPointcut(String name, World world) {
            throw new UnsupportedOperationException("Not yet implemenented");
        }
+       
+       /**
+        * @return true if assignable to java.lang.Exception
+        */
+       public boolean isException() {
+               return (world.getCoreType(UnresolvedType.JAVA_LANG_EXCEPTION).isAssignableFrom(this));
+       }
+       
+       /**
+        * @return true if it is an exception and it is a checked one, false otherwise.
+        */
+       public boolean isCheckedException() {
+               if (!isException()) return false;
+               if (world.getCoreType(UnresolvedType.RUNTIME_EXCEPTION).isAssignableFrom(this)) return false;
+               return true;
+       }
 
        /**
         * Determines if variables of this type could be assigned values of another