--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="test.Monitor"/>
+ </aspects>
+</aspectj>
--- /dev/null
+package test;
+
+public class Main {
+ public static void main(String[] args) {
+ new Main().foo();
+ }
+
+ @PerformanceMonitor(expected=1000)
+ public void foo() {
+
+ }
+}
--- /dev/null
+package test;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+@Aspect
+class Monitor {
+ @Pointcut(value="execution(@PerformanceMonitor * *(..)) && @annotation(monitoringAnnot)", argNames="monitoringAnnot")
+ public void monitored(PerformanceMonitor monitoringAnnot) {}
+
+ // Not enough entries in argNames
+ @Around(value="monitored(monitoringAnnot)", argNames="pjp")
+ public Object flagExpectationMismatch(ProceedingJoinPoint pjp, PerformanceMonitor monitoringAnnot) throws Throwable {
+ //long start = System.nanoTime();
+ Object ret = pjp.proceed();
+ //long end = System.nanoTime();
+
+ //if(end - start > monitoringAnnot.expected()) {
+ // System.out.println("Method " + pjp.getSignature().toShortString() + " took longer than expected\n\t"
+ // + "Max expected = " + monitoringAnnot.expected() + ", actual = " + (end-start));
+ //}
+
+ System.out.println("This method was intercepted by the advice: "+pjp.getSignature().toShortString());
+ return ret;
+ }
+}
+
--- /dev/null
+package test;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface PerformanceMonitor {
+ public int expected();
+}
--- /dev/null
+Error scenario one
+- incorrect number of 'names' in argNames compared the method it is attached to
--- /dev/null
+javac *.java -d .
+jar -cvMf code.jar test
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="test.Monitor"/>
+ </aspects>
+</aspectj>
--- /dev/null
+package test;
+
+public class Main {
+ public static void main(String[] args) {
+ new Main().foo();
+ }
+
+ @PerformanceMonitor(expected=1000)
+ public void foo() {
+
+ }
+}
--- /dev/null
+package test;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+@Aspect
+class Monitor {
+ @Pointcut(value="execution(@PerformanceMonitor * *(..)) && @annotation(monitoringAnnot)", argNames="monitoringAnnot")
+ public void monitored(PerformanceMonitor monitoringAnnot) {}
+
+ // Not enough entries in argNames
+ @Around(value="monitored(monitoringAnnot)", argNames="")
+ public Object flagExpectationMismatch(ProceedingJoinPoint pjp, PerformanceMonitor monitoringAnnot) throws Throwable {
+ //long start = System.nanoTime();
+ Object ret = pjp.proceed();
+ //long end = System.nanoTime();
+
+ //if(end - start > monitoringAnnot.expected()) {
+ // System.out.println("Method " + pjp.getSignature().toShortString() + " took longer than expected\n\t"
+ // + "Max expected = " + monitoringAnnot.expected() + ", actual = " + (end-start));
+ //}
+
+ System.out.println("This method was intercepted by the advice: "+pjp.getSignature().toShortString());
+ return ret;
+ }
+}
+
--- /dev/null
+package test;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface PerformanceMonitor {
+ public int expected();
+}
--- /dev/null
+Error scenario two
+- blank argNames supplied
--- /dev/null
+javac *.java -d .
+jar -cvMf code.jar test
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="test.Monitor"/>
+ </aspects>
+</aspectj>
--- /dev/null
+package test;
+
+public class Main {
+ public static void main(String[] args) {
+ new Main().foo();
+ }
+
+ @PerformanceMonitor(expected=1000)
+ public void foo() {
+
+ }
+}
--- /dev/null
+package test;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+
+class Foo {}
+
+@Aspect
+class Monitor {
+ @Around(value="execution(* *(..))",argNames="")
+ public void b(Foo aa) {}
+ @Pointcut(value="execution(* *(..))",argNames="")
+ public void a(Foo aa) {}
+ @Before(value="execution(* *(..))",argNames="")
+ public void c(Foo aa) {}
+ @After(value="execution(* *(..))",argNames="a,b,c")
+ public void d(Foo aa) {}
+ @AfterThrowing(value="execution(* *(..))",argNames="")
+ public void e(Foo aa) {}
+ @AfterReturning(value="execution(* *(..))",argNames="")
+ public void f(Foo aa) {}
+}
+
--- /dev/null
+package test;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface PerformanceMonitor {
+ public int expected();
+}
--- /dev/null
+Error scenario two
+- wrong argNames for multiple pieces of advice
--- /dev/null
+javac *.java -d .
+jar -cvMf code.jar test
--- /dev/null
+rebuilding code.jar is done with:
+
+javac *.java
+jar -cvMf code.jar test
+
+Basically you need to ensure the classes have no local variable tables - that is the default behaviour for javac
+
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="test.Monitor"/>
+ </aspects>
+</aspectj>
--- /dev/null
+package test;
+
+public class Main {
+ public static void main(String[] args) {
+ new Main().foo();
+ }
+
+ @PerformanceMonitor(expected=1000)
+ public void foo() {
+
+ }
+}
--- /dev/null
+package test;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+@Aspect
+class Monitor {
+ @Pointcut(value="execution(@PerformanceMonitor * *(..)) && @annotation(monitoringAnnot)", argNames="monitoringAnnot")
+ public void monitored(PerformanceMonitor monitoringAnnot) {}
+
+ @Around(value="monitored(monitoringAnnot)", argNames="pjp, monitoringAnnot")
+ public Object flagExpectationMismatch(ProceedingJoinPoint pjp, PerformanceMonitor monitoringAnnot) throws Throwable {
+ //long start = System.nanoTime();
+ Object ret = pjp.proceed();
+ //long end = System.nanoTime();
+
+ //if(end - start > monitoringAnnot.expected()) {
+ // System.out.println("Method " + pjp.getSignature().toShortString() + " took longer than expected\n\t"
+ // + "Max expected = " + monitoringAnnot.expected() + ", actual = " + (end-start));
+ //}
+
+ System.out.println("This method was intercepted by the advice: "+pjp.getSignature().toShortString());
+ return ret;
+ }
+}
+
--- /dev/null
+package test;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface PerformanceMonitor {
+ public int expected();
+}
// runTest("new pointcut designators in a reference pointcut");
// }
+ public void testArgNamesDoesNotWork_pr148381_1() { runTest("argNames does not work - simple");}
+ public void testArgNamesDoesNotWork_pr148381_2() { runTest("argNames does not work - error1");}
+ public void testArgNamesDoesNotWork_pr148381_3() { runTest("argNames does not work - error2");}
+ public void testArgNamesDoesNotWork_pr148381_4() { runTest("argNames does not work - error3");}
//public void testAsteriskInAtPointcut_pr209051() { runTest("asterisk in at aj pointcut");}
public void testDecpProblemWhenTargetAlreadyImplements_pr169432_1() { runTest("declare parents problem when target already implements interface - 1");}
public void testDecpProblemWhenTargetAlreadyImplements_pr169432_2() { runTest("declare parents problem when target already implements interface - 2");}
<!-- AspectJ v1.6.0 Tests -->
<suite>
+
+ <ajc-test dir="bugs154/pr148381/simple" title="argNames does not work - simple">
+ <!-- this compile is just to get code.jar into the sandbox, all the code is already precompiled in code.jar -->
+ <compile options="-1.5" files="PerformanceMonitor.java" classpath="code.jar"/>
+ <run class="test.Main" classpath="code.jar" ltw="META-INF/aop.xml">
+ <stdout>
+ <line text="This method was intercepted by the advice: Main.foo()"/>
+ </stdout>
+ <stderr/>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs154/pr148381/error1" title="argNames does not work - error1">
+ <!-- this compile is just to get code.jar into the sandbox, all the code is already precompiled in code.jar -->
+ <compile options="-1.5" files="PerformanceMonitor.java" classpath="code.jar"/>
+ <run class="test.Main" classpath="code.jar" ltw="META-INF/aop.xml">
+ <stderr>
+ <line text="argNames annotation value does not specify the right number of argument names for the method 'Object flagExpectationMismatch(ProceedingJoinPoint,PerformanceMonitor)'"/>
+ <line text="Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)"/>
+ </stderr>
+ <stdout/>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs154/pr148381/error2" title="argNames does not work - error2">
+ <!-- this compile is just to get code.jar into the sandbox, all the code is already precompiled in code.jar -->
+ <compile options="-1.5" files="PerformanceMonitor.java" classpath="code.jar"/>
+ <run class="test.Main" classpath="code.jar" ltw="META-INF/aop.xml">
+ <stderr>
+ <line text="argNames annotation value does not specify the right number of argument names for the method 'Object flagExpectationMismatch(ProceedingJoinPoint,PerformanceMonitor)'"/>
+ <line text="Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)"/>
+ </stderr>
+ <stdout/>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs154/pr148381/error3" title="argNames does not work - error3">
+ <!-- this compile is just to get code.jar into the sandbox, all the code is already precompiled in code.jar -->
+ <compile options="-1.5" files="PerformanceMonitor.java" classpath="code.jar"/>
+ <run class="test.Main" classpath="code.jar" ltw="META-INF/aop.xml">
+ <stderr>
+ <line text="argNames annotation value does not specify the right number of argument names for the method 'void a(Foo)'"/>
+ <line text="Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)"/>
+ <line text="argNames annotation value does not specify the right number of argument names for the method 'void f(Foo)'"/>
+ <line text="Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)"/>
+ <line text="argNames annotation value does not specify the right number of argument names for the method 'void e(Foo)'"/>
+ <line text="Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)"/>
+ <line text="argNames annotation value does not specify the right number of argument names for the method 'void d(Foo)'"/>
+ <line text="Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)"/>
+ <line text="argNames annotation value does not specify the right number of argument names for the method 'void c(Foo)'"/>
+ <line text="Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)"/>
+ <line text="argNames annotation value does not specify the right number of argument names for the method 'void b(Foo)'"/>
+ <line text="Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)"/>
+ </stderr>
+ <stdout/>
+ </run>
+ </ajc-test>
+
<ajc-test dir="bugs154/pr209051" title="asterisk in at aj pointcut">
<compile options="-1.5" files="Bug.java"/>
<run class="Bug">