Bug 124654

Summary: Capture method annotation in generic aspect does not compile
Product: [Tools] AspectJ Reporter: hesse
Component: CompilerAssignee: Andrew Clement <aclement>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 1.5.0   
Target Milestone: 1.5.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description hesse CLA 2006-01-20 10:32:07 EST
The following aspect won't compile with aspect 1.5:

package aj;

import java.lang.annotation.Annotation;

public abstract aspect GenericAnnotation<A extends Annotation> {

    pointcut annotatedCall(A a) : call(@A * *.*(..)) && @annotation(a);

    /* does not compile */
    before(A a) : annotatedCall(a) {
        System.out.println(a.annotationType());
    }
    /* */

    /* OK */
    before(A a) : call(@A * *.*(..)) && @annotation(a) {
        System.out.println(a.annotationType());
    }

}

----------------------

>ajc -1.5 -d aj src\aj\*
...\src\aj\GenericAnnotation.aj:10 [error] incompatible type, expected java.lang.annotation.Annotation found BindingTypePattern(TA;, 0).  Check the type specified in your pointcut before(A a) : annotatedCall(a) {

1 error

----------------

Commenting out the first advice lets this program run as expected:

package aj;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class Main {

    @Retention(RetentionPolicy.RUNTIME)
    @interface MyAnnotation {
    }

    static aspect ConcreteAnnotation extends GenericAnnotation<MyAnnotation> {
    }

    public static void main(String[] args) {
        someMethod();
    }

    @MyAnnotation
    private static void someMethod() {
    }

}
Comment 1 Andrew Clement CLA 2006-01-20 12:11:00 EST
appears the code putting out the message isnt being smart about encountering type variables...
Comment 2 Andrew Clement CLA 2006-01-23 10:20:03 EST
fix checked in.
Comment 3 Andrew Clement CLA 2006-01-24 06:15:27 EST
fix available.