]> source.dussan.org Git - aspectj.git/commitdiff
testcode for 129282
authoraclement <aclement>
Wed, 31 May 2006 10:09:27 +0000 (10:09 +0000)
committeraclement <aclement>
Wed, 31 May 2006 10:09:27 +0000 (10:09 +0000)
tests/bugs152/pr129282/AdviceExecution.aj [new file with mode: 0644]
tests/bugs152/pr129282/ConstructorCall.aj [new file with mode: 0644]
tests/bugs152/pr129282/ConstructorExecution.aj [new file with mode: 0644]
tests/bugs152/pr129282/ExceptionHandler.aj [new file with mode: 0644]
tests/bugs152/pr129282/Initialization.aj [new file with mode: 0644]
tests/bugs152/pr129282/InnerMethodCall.aj [new file with mode: 0644]
tests/bugs152/pr129282/InnerMethodCall2.aj [new file with mode: 0644]
tests/bugs152/pr129282/MethodCall.aj [new file with mode: 0644]
tests/bugs152/pr129282/MethodCallInDiffClass.aj [new file with mode: 0644]
tests/bugs152/pr129282/MethodExecution.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc152/ajc152.xml

diff --git a/tests/bugs152/pr129282/AdviceExecution.aj b/tests/bugs152/pr129282/AdviceExecution.aj
new file mode 100644 (file)
index 0000000..9171f2f
--- /dev/null
@@ -0,0 +1,27 @@
+import java.io.FileNotFoundException;
+
+import org.aspectj.lang.annotation.AdviceName;
+
+public aspect AdviceExecution {
+       
+       // don't want the 'declared exception not actually
+       // thrown' warning against this piece of advice
+       @AdviceName("Test")
+       before() throws FileNotFoundException : execution(* C.method1(..)) {    
+       }
+       
+       before(AdviceName name) throws FileNotFoundException : adviceexecution() 
+               && @annotation(name)
+               && if(name.value().indexOf("Test") != -1) {
+                       throw new FileNotFoundException();
+       }
+
+}
+
+class C {
+       
+       // don't want the 'declared exception not actually 
+       // thrown' warning
+       public void method1() throws FileNotFoundException {
+       }
+}
diff --git a/tests/bugs152/pr129282/ConstructorCall.aj b/tests/bugs152/pr129282/ConstructorCall.aj
new file mode 100644 (file)
index 0000000..6bae499
--- /dev/null
@@ -0,0 +1,23 @@
+import java.io.FileNotFoundException;
+
+public aspect ConstructorCall {
+
+       pointcut p() : call(public C1.new());
+       
+       before() throws FileNotFoundException : p() { 
+               throw new FileNotFoundException();
+       }
+       
+}
+
+class C1 {
+       
+       // shouldn't get the warning against the constructor
+       public C1() throws FileNotFoundException {      
+       }
+       
+       public void m1() throws FileNotFoundException {
+               new C1();
+       }
+       
+}
diff --git a/tests/bugs152/pr129282/ConstructorExecution.aj b/tests/bugs152/pr129282/ConstructorExecution.aj
new file mode 100644 (file)
index 0000000..816f223
--- /dev/null
@@ -0,0 +1,19 @@
+import java.io.FileNotFoundException;
+
+public aspect ConstructorExecution {
+
+       pointcut p1() : execution(public C1.new());
+       
+       before() throws FileNotFoundException : p1() {
+               throw new FileNotFoundException();
+       }
+       
+}
+
+class C1 {
+       
+       // shouldn't get the warning on this constructor
+       public C1() throws FileNotFoundException {      
+       }
+       
+}
diff --git a/tests/bugs152/pr129282/ExceptionHandler.aj b/tests/bugs152/pr129282/ExceptionHandler.aj
new file mode 100644 (file)
index 0000000..3ff3f47
--- /dev/null
@@ -0,0 +1,39 @@
+// with the exception handler, the advice isn't actually throwing the
+// exception for the method - therefore, expect warnings when the methods
+// don't throw the exception themselves.
+public aspect ExceptionHandler {
+
+       pointcut p() : handler(*);
+       
+       before() throws MyException : p() {
+               throw new MyException();
+       }
+       
+       
+}
+
+class C {
+       
+       public void method1() {
+               try {
+                       new C().throwingMethod();
+                       new C().throwingMethod2();
+               } catch (MyException e) {
+                       e.printStackTrace();
+               }
+       }
+       
+       // dont want 'declared exception not actually thrown'
+       // warning for this method because it's throwing it
+       public void throwingMethod() throws MyException {
+               throw new MyException();
+       }
+       
+       // do want 'declared exception not actually thrown'
+       // warning because it doesn't throw it
+       public void throwingMethod2() throws MyException {
+       }
+}
+
+class MyException extends Exception {
+}
diff --git a/tests/bugs152/pr129282/Initialization.aj b/tests/bugs152/pr129282/Initialization.aj
new file mode 100644 (file)
index 0000000..c3c360b
--- /dev/null
@@ -0,0 +1,30 @@
+import java.io.FileNotFoundException;
+
+public aspect Initialization {
+
+       pointcut preInit() : preinitialization(C.new(String));
+       
+       before() throws FileNotFoundException : preInit() {
+               throw new FileNotFoundException();
+       }
+       
+       pointcut init() : initialization(C.new());
+       
+       before() throws FileNotFoundException : init() {
+               throw new FileNotFoundException();
+       }
+}
+
+class C {
+       
+       // shouldn't get a warning against this constructor  
+       // since the throwing is handled by the advice
+       public C() throws FileNotFoundException {
+       }
+       
+       // shouldn't get a warning against this constructor
+       // since the throwing is handled by the advice
+       public C(String s) throws FileNotFoundException {
+       }
+       
+}
diff --git a/tests/bugs152/pr129282/InnerMethodCall.aj b/tests/bugs152/pr129282/InnerMethodCall.aj
new file mode 100644 (file)
index 0000000..ed1f54c
--- /dev/null
@@ -0,0 +1,52 @@
+import java.io.FileNotFoundException;
+
+public aspect InnerMethodCall {
+
+       pointcut p() : call(public * C1.m2());
+       
+       before() throws FileNotFoundException : p() { 
+               throw new FileNotFoundException();
+       }
+       
+       pointcut p2() : call(public * C1.m4());
+       
+       before() : p2() {
+       }
+       
+}
+
+class C1 {
+       
+       public void m1() {
+               new C2() {
+                       public void m6() throws FileNotFoundException {
+                               new C1().m2();
+                       }
+               };
+       }
+       
+       // don't want the 'declared exception not actually
+       // thrown' warning because the advice is affecting
+       // this method
+       public void m2() throws FileNotFoundException {         
+       }
+       
+       public void m3() {
+               new C2() {
+                       public void m6() throws FileNotFoundException {
+                               new C1().m4();
+                       }
+               };
+       }
+       
+       // do want the 'declared exception not actually
+       // thrown' warning
+       public void m4() throws FileNotFoundException {
+       }
+       
+       
+}
+
+abstract class C2 {
+       public abstract void m6() throws FileNotFoundException;
+}
diff --git a/tests/bugs152/pr129282/InnerMethodCall2.aj b/tests/bugs152/pr129282/InnerMethodCall2.aj
new file mode 100644 (file)
index 0000000..202bf88
--- /dev/null
@@ -0,0 +1,40 @@
+import java.io.FileNotFoundException;
+
+aspect InnerMethodCall2 {
+       
+       pointcut p() : call(* C1.c1Method());
+       
+       before() throws FileNotFoundException : p() {
+               throw new FileNotFoundException();
+       }
+       
+}
+
+class MainClass {
+       
+       public void amethod() {
+               new C() {
+                       public void mymethod() throws FileNotFoundException {
+                               new C() {
+                                       public void mymethod() throws FileNotFoundException {
+                                               new C1().c1Method();
+                                       }
+                               };
+                       }
+               };
+       }
+       
+}
+
+class C1 {
+       
+       // don't want the 'declared exception not actually thrown'
+       // exception because the advice is effectively throwing it
+       public void c1Method() throws FileNotFoundException {
+       }
+       
+}
+
+abstract class C {
+       public abstract void mymethod() throws FileNotFoundException;
+}
diff --git a/tests/bugs152/pr129282/MethodCall.aj b/tests/bugs152/pr129282/MethodCall.aj
new file mode 100644 (file)
index 0000000..b05c899
--- /dev/null
@@ -0,0 +1,38 @@
+import java.io.FileNotFoundException;
+
+public aspect MethodCall {
+
+       pointcut p() : call(public * C1.m2());
+       
+       before() throws FileNotFoundException : p() { 
+               throw new FileNotFoundException();
+       }
+       
+       pointcut p2() : call(public * C1.m4());
+       
+       before() : p2() {
+       }
+       
+}
+
+class C1 {
+       
+       public void m1() throws FileNotFoundException {
+               new C1().m2();
+       }
+       
+       // don't want the 'declared exception not actually
+       // thrown' warning because the advice is affecting
+       // this method
+       public void m2() throws FileNotFoundException {         
+       }
+       
+       public void m3() throws FileNotFoundException {
+               new C1().m4();
+       }
+       
+       // do want the 'declared exception not actually
+       // thrown' warning
+       public void m4() throws FileNotFoundException {
+       }
+}
diff --git a/tests/bugs152/pr129282/MethodCallInDiffClass.aj b/tests/bugs152/pr129282/MethodCallInDiffClass.aj
new file mode 100644 (file)
index 0000000..f63e551
--- /dev/null
@@ -0,0 +1,28 @@
+import java.io.FileNotFoundException;
+
+public aspect MethodCallInDiffClass {
+
+       pointcut p() : call(public * B1.m2());
+       
+       before() throws FileNotFoundException : p() { 
+               throw new FileNotFoundException();
+       }
+       
+}
+
+class B {
+       
+       public void m1() throws FileNotFoundException {
+               new B1().m2();
+       }
+       
+}
+
+class B1 {
+       
+       // don't want the 'declared exception not acutally
+       // thrown' warning since the advice is throwing it
+       public void m2() throws FileNotFoundException { 
+       }
+       
+}
diff --git a/tests/bugs152/pr129282/MethodExecution.aj b/tests/bugs152/pr129282/MethodExecution.aj
new file mode 100644 (file)
index 0000000..45224f7
--- /dev/null
@@ -0,0 +1,33 @@
+import java.sql.SQLException;
+
+public aspect MethodExecution {
+
+       pointcut pc() : execution(public * C.shouldntThrow(..));
+       
+       Object around() throws SQLException :pc(){
+               throw new SQLException(); 
+       }
+       
+       pointcut pc2() : execution(public * C.needsToThrow(..));
+       
+       // C.needsToThrow still needs to throw the exception because
+       // this advice isn't doing anything with exceptions
+       before() : pc2() {
+       }
+       
+}
+
+class C {
+       
+       // don't want the "declared exception is not actually
+       // thrown" message because around advice is affecting
+       // this method
+       public void shouldntThrow() throws SQLException {
+       }
+
+       // do want the "declared exception is not actually
+       // thrown" message to appear for this method
+       public void needsToThrow() throws SQLException{
+       }
+       
+}
index 557d8182c586ad623e663db93123745086b853f9..b8ff2b5860fd5512091433bf40362bee58b8b470 100644 (file)
       </compile>
     </ajc-test>
     
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 1">
+      <compile files="MethodExecution.aj" options="-warn:+unusedThrown">
+               <message kind="warning" line="30" text="The declared exception SQLException is not actually thrown by the method needsToThrow() from type C"/>
+         </compile>
+    </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 2">
+      <compile files="MethodCall.aj" options="-warn:+unusedThrown">
+               <message kind="warning" line="36" text="The declared exception FileNotFoundException is not actually thrown by the method m4() from type C1"/>
+         </compile>
+    </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 3">
+      <compile files="InnerMethodCall.aj" options="-warn:+unusedThrown">
+               <message kind="warning" line="44" text="The declared exception FileNotFoundException is not actually thrown by the method m4() from type C1"/>
+         </compile>
+    </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 4">
+      <compile files="AdviceExecution.aj" options="-1.5 -warn:+unusedThrown"/>
+       </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 5">
+      <compile files="ExceptionHandler.aj" options="-warn:+unusedThrown">
+               <message kind="warning" line="34" text="The declared exception MyException is not actually thrown by the method throwingMethod2() from type C"/>
+         </compile>
+       </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 6">
+      <compile files="Initialization.aj" options="-warn:+unusedThrown"/>
+       </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 7">
+      <compile files="ConstructorCall.aj" options="-warn:+unusedThrown"/>
+       </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 8">
+      <compile files="ConstructorExecution.aj" options="-warn:+unusedThrown"/>
+       </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 9">
+      <compile files="MethodCallInDiffClass.aj" options="-warn:+unusedThrown"/>
+    </ajc-test>
+
+    <ajc-test dir="bugs152/pr129282" title="no unnecessary declaration of thrown exception warning - 10">
+      <compile files="InnerMethodCall2.aj" options="-warn:+unusedThrown"/>
+    </ajc-test>
+
     <ajc-test dir="bugs152/pr138215" pr="138215" title="Reference pointcut fails inside @DeclareWarning">
       <compile files="pr138215.aj" options="-1.5">
         <message kind="warning" line="17" text="no foos please"/>