Community
Participate
Working Groups
MyEnum.java =========== public enum MyEnum { ONE, TWO, THREE, FOUR, FIVE } --- MyAnnotation.java ================= import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { MyEnum[] value(); } --- MyClass.java ============ public class MyClass { public MyEnum getValue() { return MyEnum.ONE; } @MyAnnotation({ MyEnum.ONE, MyEnum.TWO }) public void test() { } public static void main(String[] args) { new MyClass().test(); } } --- MyAspect.aj =========== import java.util.Arrays; privileged public aspect MyAspect { Object around(MyClass o, MyAnnotation a) : execution(@MyAnnotation * *(..)) && target(o) && @annotation(a) { if (!isOneOf(o.getValue(), a.value())) throw new IllegalStateException( o.getValue() + " is not one of " + Arrays.toString(a.value())); return proceed(o, a); } private static final <T> boolean isOneOf(T obj, T[] arr) { for (T el : arr) if (obj == el) return true; return false; } } --- Executing the main method of MyClass produces: Exception in thread "main" java.lang.NoSuchMethodError: MyAspect.isOneOf(LMyEnum;[LMyEnum;)Z at MyAspect.ajc$privMethod$MyAspect$MyAspect$isOneOf(MyAspect.aj:1) at MyClass.test_aroundBody1$advice(MyClass.java:109) at MyClass.test(MyClass.java:1) at MyClass.main(MyClass.java:12) --- What's interesting is that if you remove the "privileged" modifier from the aspect definition, then it works fine.
fix committed - will be in next dev build. the privilege accessor generation code wasnt aware of generic methods.
fix available in latest AJ dev build.