Bug 287597 - Relative order of annotation vs. access specification should not matter
Summary: Relative order of annotation vs. access specification should not matter
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-25 14:10 EDT by Ramnivas Laddad CLA
Modified: 2013-06-24 11:05 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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