Community
Participate
Working Groups
This code == bangbang ----8<----- enum Color {R,G,B;} @interface I { public Color a(); } @interface J { public Color b() default Color.B; } public class A { @J @I(a=Color.R) public static void main(String []argv) { } } aspect X { before(Color var): execution(* main(..)) && @annotation(I(var)) { if (var!=Color.R) { throw new RuntimeException("Wrong! Was "+var); } } } ----8<----- Exception in thread "main" java.lang.VerifyError: (class: A, method: main signat ure: ([Ljava/lang/String;)V) Incompatible object argument for function call
No attempt is made to check the annotation we are grabbing the Color from - we go through all those on the join point and pull out a Color from any we find. We should be checking the type matches first! In this case that the annotation is of type 'I' before we pull out its Color value. The fix is in AnnotationAccessFieldVar. Testcase and fix committed. (The verifyerror happened because two Colors were put on the stack and when the advice method was called we tried to call it on the enum type rather than the aspect instance!)