Bug 287597

Summary: Relative order of annotation vs. access specification should not matter
Product: [Tools] AspectJ Reporter: Ramnivas Laddad <ramnivas>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: aclement
Version: DEVELOPMENT   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Ramnivas Laddad CLA 2009-08-25 14:10:39 EDT
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++;
        }
    }
}
Comment 1 Andrew Clement CLA 2009-08-26 15:44:34 EDT
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...
Comment 2 Andrew Clement CLA 2013-06-24 11:05:40 EDT
unsetting the target field which is currently set for something already released