JDK-6876891 : JSR 308 type annotations not visible when processing java source files starting b70
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.annotation.processing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-08-28
  • Updated: 2013-06-21
  • Resolved: 2013-06-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
The JSR 308 type annotations on type parameters are not visible when doing the
annotation processing of java *source* files starting b70. For example, if I compile the sample class T below and run my simple annotation processor (source attached) that prints the contents of a processed java class, then the "@X" annotation on the "A" type variable is not printed out:

====
import java.lang.annotation.*;

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

public class T {
     public <@X A> void foo() {}
}
====

# jdk7_b70/bin/javac MyProcessor.java T.java
# jdk7_b70/bin/javac -processor MyProcessor T.java
TypeParam: A
TypeParamAnnotation:

However, the annotation processing of the java source works fine with b64 - b69:

# jdk7_69/bin/javac -processor MyProcessor T.java
TypeParam: A
TypeParamAnnotation: @X

Comments
assign to Joel (after the fact) since he put in fix for JDK-8011027 which remedied this bug also.
21-06-2013

This was probably due to type-annotations being removed from jdk7. While it was put back in 8, processing was not working until JDK-8011027 Type parameter annotations not passed through to javax.lang.model was fixed in jdk8 b89( http://hg.openjdk.java.net/jdk8/jdk8/langtools/rev/bae8387d16aa )
21-06-2013

EVALUATION Looking at the bugs fixed in b70, the likely offender is 6861837. The corresponding changeset is here http://hg.openjdk.java.net/jdk7/tl/langtools/rev/6d0add6ad778. Of note is the following lines deleted from MemberEnter: $ hg diff -r 335 -r 336 src/share/classes/com/sun/tools/javac/comp/MemberEnter.java diff -r dd5c51734ad9 -r 6d0add6ad778 src/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Jul 30 10:30:24 2009 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Jul 30 10:30:34 2009 +0100 @@ -1040,15 +1040,6 @@ JavaFileObject prev = log.useSource(env.toplevel.sourcefile); try { enterTypeAnnotations(annotations); - - // enrich type parameter symbols... easier for annotation processors - if (tree instanceof JCTypeParameter) { - JCTypeParameter typeparam = (JCTypeParameter)tree; - ListBuffer<Attribute.Compound> buf = ListBuffer.lb(); - for (JCTypeAnnotation anno : annotations) - buf.add(anno.attribute_field); - typeparam.type.tsym.attributes_field = buf.toList(); - } } finally { log.useSource(prev); }
30-09-2010

EVALUATION I confirm the failure started in b70. A regression test for the failure passes in b69, but fails in b70.
30-09-2010