review request for 8010225 test in typeAnnotations/failures do not test TYPE_USE

Alex Buckley alex.buckley at
Tue Sep 17 12:29:32 PDT 2013

To all: there's a bug in case 4 below.

On 9/17/2013 12:06 PM, Steve Sides wrote:
> Got it. While whittling on this, I have another question about the
> compiler's behavior.
> 1. If I qualify the (not type) annotation,
>    @Scopes.UniqueInner
>    class Scopes<T extends @Scopes.UniqueInner Object> {
>       @interface UniqueInner { };
>    }
> I get 1 error, "
> compiler.err.annotation.type.not.applicable". This seems correct as I'm
> using an annotation on a type usage, and the one on the class is okay.

You are right. The annotation on the upper bound of T is illegal because 
the Scopes.UniqueInner annotation type is applicable only in locations 
which existed in Java SE 7 (such as type declarations) and not in new 
locations in Java SE 8 (such as type uses).

> 2. If I use the annotation unqualified, I get 3 errors, two for
> "cant.resolve..." and the one above again. I can see that this can also
> be correct.
> compiler.err.cant.resolve: kindname.class,
> UniqueInner, ,  // on the class
> compiler.err.cant.resolve: kindname.class,
> UniqueInner, , // on the bound
> compiler.err.annotation.type.not.applicable               // not a type
> annotation(I assumed)?
> 3 errors

The scope of the @interface declaration is the body of class Scopes. 
Therefore, the simple name "UniqueInner" is not in scope before the { of 
the declaration of Scopes. All three errors are correct.

> 3. If I use a qualified type annotation,
> @Scopes.UniqueInner
> class Scopes<T extends @Scopes.UniqueInner Object> {
>      @Target(ElementType.TYPE_USE)
>      @interface UniqueInner { };
> }
> it compiles without error.

As it should.

> 4. However, if I use an unqualified type annotation,
> @UniqueInner
> class Scopes<T extends @UniqueInner Object> {
>      @Target(ElementType.TYPE_USE)
>      @interface UniqueInner { };
> }
>   I get the same 3 errors as the unqualified annotation:
> compiler.err.cant.resolve: kindname.class, UniqueInner, ,
> compiler.err.cant.resolve: kindname.class,
> UniqueInner, ,
> compiler.err.annotation.type.not.applicable
> 3 errors
> Why should I get "compiler.err.annotation.type.not.applicable" in this
> last scenario?  For 1. I kind of assumed the third error meant it was
> not applicable because it was not a type annotation.  Is it not
> applicable for reasons other than not being TYPE_USE?

You are right to ponder what's going on. The third error, about 
applicability, is a bug.

> I'm thinking of using it as below (and adding a postivie version with
> qualified name),
> @UniqueInner
> class Scopes<T extends @UniqueInner Object>  {
>      // Unqualified @UniqueInner is not accessible to the class .
>      // One has to use @Scopes.UniqueInner.
>      @Target(ElementType.TYPE_USE)
>      @interface UniqueInner { };
> }
> but I'm unsure about that third error and would like to verify it is as
> expected.

Please add this test. The comment however should not mention 
accessibility, which is a totally different concept. Say "The simple 
name UniqueInner is not in scope on the header of class Scopes, so 
@UniqueInner is not meaningful there. One must use the qualified name, 
as in @Scopes.UniqueInner."

In addition, the type parameter T is also out of UniqueInner's scope. To 
ensure that annotations on the class declaration and annotations on the 
type parameter declaration are handled consistently, @UniqueInner should 
be written on T as well.


More information about the type-annotations-dev mailing list