Community
Participate
Working Groups
In a pointcut expression, the relative order of the access specification to annotations should not matter. Currently, pointcut matches if annotation expression appears only before the access specification. Since in Java the relative ordering doesn't matter, it shouldn't matter in AspectJ either. Here is a test program that illustrates the problem (uses method annotations, but the problem exists for all other patterns). package test; import org.junit.Assert; import org.junit.Test; public class AnnotationModifierOrderingBug { @Test public void orderingOfAccessAndAnnotationDoesntMatter() { MyAnnotatedClass obj = new MyAnnotatedClass(); obj.aMethod(); Assert.assertEquals(1, MyAspect.aspectOf().annotBeforeAccess); Assert.assertEquals(1, MyAspect.aspectOf().accessBeforeAnnot); } static @interface MyAnnotation { } static class MyAnnotatedClass { @MyAnnotation public void aMethod() { } } static aspect MyAspect { private int accessBeforeAnnot; private int annotBeforeAccess; before() : execution(public @MyAnnotation * *(..)) { accessBeforeAnnot++; } before() : execution(@MyAnnotation public * *(..)) { annotBeforeAccess++; } } }
If an error was produced for using them the 'unusual way round', I'd leap on this and fix it. Unfortunately it does have a meaning, if the annotation is expressed here: execution(public @Foo * *(..)) then it is associated with the return type (despite there being no parentheses) so if I change it, it may affect existing programs...
unsetting the target field which is currently set for something already released