Bug 169706 - @annotation compilation problem
Summary: @annotation compilation problem
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.3   Edit
Hardware: PC Linux
: P3 blocker (vote)
Target Milestone: 1.5.4   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-05 12:50 EST by Paulo Zenida CLA
Modified: 2007-10-10 10:21 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paulo Zenida CLA 2007-01-05 12:50:26 EST
There is a problem when the @annotation is used in a context where the annotation for the method is not declared neither in the type of the object instance nor in its super type. The following example shows the problem I have detected. The compiler throws the following exception:

java.lang.IllegalStateException
at org.aspectj.weaver.bcel.BcelShadow.getAnnotations(BcelShadow.java:1578)
at org.aspectj.weaver.bcel.BcelShadow.initializeKindedAnnotationVars(BcelShadow.java:1603)
at org.aspectj.weaver.bcel.BcelShadow.getKindedAnnotationVar(BcelShadow.java:1087)
at org.aspectj.weaver.patterns.AnnotationPointcut.findResidueInternal(AnnotationPointcut.java:195)
at org.aspectj.weaver.patterns.Pointcut.findResidue(Pointcut.java ... lasses 
when weaving 
when batch building BuildConfig[/home/pacz/workspace/.metadata/.plugins/org.eclipse.ajdt.core/MyBugTest.generated.lst] #Files=7


The example:

public class A {

    @MyAnnotation
    public void foo() {

    }

}

public class B extends A {

}

public class C extends B {

}

public class Test {

    public static void main(String args[]) {
        C c = new C();
        c.foo();
    }

}

public aspect MyAspect {

    // this throws an exception
    before(MyAnnotation myAnnotation) : 
        call(@MyAnnotation * *..*.*(..)) &&
        @annotation(myAnnotation) {

    }

    // this, however, works fine
    // before() : 
    //     call(@MyAnnotation * *..*.*(..)) {
    // 
    // }
}
Comment 1 Andrew Clement CLA 2007-01-08 10:58:16 EST
you didn't include the declaration of the annotation type - but i made one up.  The bug here is that the hierarchy is more than 2 deep.  You have A > B > C.  If you have A > C (ie. C extends A directly) then it would work without an error.

I've committed a testcase and the fix - thanks for supplying a minimal set of files that show the problem.
Comment 2 Andrew Clement CLA 2007-01-09 03:44:18 EST
fix available in latest dev build.