Community
Participate
Working Groups
Created attachment 278758 [details] Maven project reproducing the problem The compiler is incorrectly reporting to annotation processors that an annotation on a type parameter also appears on uses of that type parameter. For example, consider this class: package bug; import com.google.auto.value.AutoValue; import com.google.errorprone.annotations.ImmutableTypeParameter; @AutoValue abstract class Bug<@ImmutableTypeParameter T> { abstract T bug(); static <@ImmutableTypeParameter T> Bug<T> of(T t) { return new AutoValue_Bug<>(t); } } @ImmutableTypeParameter has @Target({TYPE_PARAMETER}), so it is only applicable to type parameters. But when an annotation processor looks at the T that is the return type of the bug() method, it gets back a TypeVariable with the @ImmutableTypeParameter annotation. This leads AutoValue to generate this code: package bug; import com.google.errorprone.annotations.ImmutableTypeParameter; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_Bug<@ImmutableTypeParameter T> extends Bug<T> { private final @ImmutableTypeParameter T bug; AutoValue_Bug( @ImmutableTypeParameter T bug) { if (bug == null) { throw new NullPointerException("Null bug"); } this.bug = bug; } @Override @ImmutableTypeParameter T bug() { return bug; } ... } The <@ImmutableTypeParameter T> in the class declaration is correctly copied, because it was returned from TypeParameterElement.getAnnotationMirrors(). However, the other three occurrences of @ImmutableTypeParameter are incorrect, and come about because TypeVariable.getAnnotationMirrors() reported that the type variable T has that annotation. This code then fails to compile, because the compiler correctly rejects @ImmutableTypeParameter applied to a type variable. It can only be applied to a type parameter. This code compiles fine with javac.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.