--- /dev/null
+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 {
+ }
+}
--- /dev/null
+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();
+ }
+
+}
--- /dev/null
+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 {
+ }
+
+}
--- /dev/null
+// 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 {
+}
--- /dev/null
+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 {
+ }
+
+}
--- /dev/null
+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;
+}
--- /dev/null
+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;
+}
--- /dev/null
+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 {
+ }
+}
--- /dev/null
+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 {
+ }
+
+}
--- /dev/null
+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{
+ }
+
+}
</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"/>