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

Steve Sides steve.sides at oracle.com
Tue Sep 17 12:06:14 PDT 2013


On 9/16/2013 5:20 PM, Alex Buckley wrote:
> On 9/16/2013 2:42 PM, Steve Sides wrote:
>> On 9/13/2013 10:42 AM, Alex Buckley wrote:
>>> - AnnotationVersion: The @summary is imprecise - the test is about the
>>> receiver parameter 'this', not type annotations in general. In SE 6
>>> and 7 and 8, the annotation type 'A' with no
>> I'm not so sure I agree with that. Due to the 3 @compile lines, the test
>> is about allowing type-annotations only with jdk8. The fact that he put
>> the annotation on 'this' appears to me to be incidental.  It may be odd
>> that he chose 'this' as opposed to maybe 'String' or some other more
>> common usage, but it does seem to be just a usage to make the general
>> point and elicit the diagnostic
>> "compiler.err.type.annotations.not.supported.in.source: 1.7", and not to
>> test that specific usage.
>
> This test aims to show that "type annotations" didn't exist and now do 
> exist. In other words, that an annotation was not permitted in some 
> type-oriented location in 6/7 but is permitted in that location in 8. 
> It is poor form to choose a location in 8 which didn't exist in 6/7 - 
> especially when that location is frankly very obscure. I would suggest 
> putting the @A on something simple like an 'extends' clause.
>
> In addition, ElementType.TYPE_USE didn't exist in 6/7 so a reader 
> might ask why javac doesn't complain about that rather than the syntax 
> error of the 'this' parameter. This is why I also suggested having a 
> companion test where a ElementType from 6/7 was used.
>
> Alex
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, "Scopes.java:11:24: 
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.

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.

Scopes.java:10:2: compiler.err.cant.resolve: kindname.class, UniqueInner, ,  // on the class
Scopes.java:11:25: compiler.err.cant.resolve: kindname.class, UniqueInner, , // on the bound
Scopes.java:11:24: compiler.err.annotation.type.not.applicable               // not a type annotation(I assumed)?
3 errors

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.

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:

Scopes.java:10:2: compiler.err.cant.resolve: kindname.class, UniqueInner, ,
Scopes.java:11:25: compiler.err.cant.resolve: kindname.class, UniqueInner, ,
Scopes.java:11:24: 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?

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.

-steve








More information about the type-annotations-dev mailing list