Bug 235597 - compiler error when exposing annotations on methods defined in generic classes
Summary: compiler error when exposing annotations on methods defined in generic classes
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.6.1   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-04 10:08 EDT by Wim Depoorter CLA
Modified: 2008-06-10 04:31 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wim Depoorter CLA 2008-06-04 10:08:48 EDT
Build ID: AspectJ Compiler 1.6.0 (1.6.0 - Built: Wednesday Apr 23, 2008 at 20:27:36 GMT) - Eclipse Compiler 0.785_R33x, 3.3

Steps To Reproduce:
1. Explanation:

Defining a pointcut that exposes the annotation of a method fails
("-- (BCException) Couldn't discover annotations for shadow: method-call") when that method is defined inside a generic class and the pointcut is defined with a 'call' construct (first piece of advice code).

It succeeds when using the 'execution' construct however (second piece of advice code), or when not exposing the annotation itself (third piece of advice code).

It is desirable to be able to expose both the annotation (to read its values) and the caller as well, also when the callee method is defined in a generic class.

2. Sample Code (either comment out first advice or CASE2 to be able to compile).


==Annotation==
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SomeAnnotation {

}
==

==aspect==
public aspect SomeAspect {
	
	void around(final SomeAnnotation someAnnotation) :
		call(@SomeAnnotation void *.*(..)) && @annotation(someAnnotation) {
		
		System.out.println("@someAspect annotation parameter (call)"); //CASES 1, 3 only
		proceed(someAnnotation);
	}

	void around(final SomeAnnotation someAnnotation) :
		execution(@SomeAnnotation void *.*(..)) && @annotation(someAnnotation) {
		
		System.out.println("@someAspect annotation parameter (execution)"); //CASES 1, 2, 3
		proceed(someAnnotation);
	}

	void around() :	call(@SomeAnnotation void *.*(..)) {
		System.out.println("@someAspect annotation no parameter"); //CASES 1, 2, 3
		proceed();
	}

	void around() :	call(void *.test*(..)) {
		System.out.println("@someAspect method name"); //CASES 1, 2, 3
		proceed();
	}
}
==

==TestClass==
public class AnnotationTest1 {
	
	@SomeAnnotation
	public void test() {
		System.out.println("test 1");
	}

	public static void main(String[] args) {
		//CASE 1
		AnnotationTest1 test1 = new AnnotationTest1();
		test1.test();
		//CASE 2
		AnnotationTest2<Integer> test2 = new AnnotationTest2<Integer>();
		test2.test2();
		//CASE 3
		AnnotationTest3 test3 = new AnnotationTest3();
		test3.test3();
	}
	
	public static class AnnotationTest2 <Type extends Object> {
		
		@SomeAnnotation
		public void test2() {
			System.out.println("test 2");
		}
	}
	
	public static class AnnotationTest3 extends AnnotationTest2<Double> {
		
		@SomeAnnotation
		public void test3() {
			System.out.println("test 3");
		}
	}
}
==


More information:
Bug also occurs in latest Eclipse AJDT (version 1.5.3.20080611729) with the following AspectJ internal compiler error:

org.aspectj.weaver.BCException
at org.aspectj.weaver.bcel.BcelShadow.initializeKindedAnnotationVars(BcelShadow.java:1662)
at org.aspectj.weaver.bcel.BcelShadow.getKindedAnnotationVar(BcelShadow.java:1099)
at org.aspectj.weaver.patterns.AnnotationPointcut.findResidueInternal(AnnotationPointcut.java:211)
at org.aspectj.weaver.patterns.Pointcut.findResidue(Pointcut.java:269)
at org.aspectj.weaver.patterns.AndPointcut.findResidueInternal(AndPoin ... otationError.SomeAspect, annotationError.SomeAnnotation, org.aspectj.runtime.internal.AroundClosure)
Comment 1 Andrew Clement CLA 2008-06-04 13:21:33 EDT
thanks for the great bug report and testcase.  I've just committed the fix for this into AspectJ - will be in AJDT in a few days. 

There could be other issues around annotation matching/binding and generics...
Comment 2 Wim Depoorter CLA 2008-06-10 04:31:27 EDT
(In reply to comment #1)
> thanks for the great bug report and testcase.  I've just committed the fix for
> this into AspectJ - will be in AJDT in a few days. 
> 
> There could be other issues around annotation matching/binding and generics...
> 

I can confirm it is working in AJDT build 1.5.3.200806091332. Many thanks for the fast reply and fix! If I find any other issues around annotation matching/binding and generics, I'll be sure to report them.

regards,

Wim