RFR: 8043226: Better diagnostics for non-applicable type annotations [v2]

Liam Miller-Cushon cushon at openjdk.org
Mon Jan 8 19:20:24 UTC 2024


On Mon, 8 Jan 2024 16:36:44 GMT, Werner Dietl <wmdietl at openjdk.org> wrote:

>> Liam Miller-Cushon has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Update src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
>>   
>>   Co-authored-by: Werner Dietl <wdietl at gmail.com>
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties line 3233:
> 
>> 3231: # 0: fragment, 1: symbol, 2: type
>> 3232: compiler.err.type.annotation.inadmissible=\
>> 3233:     type annotations are not admissible at this location: {0}\n\
> 
> Suggestion:
> 
> compiler.err.type.annotation.not.applicable=\
>     type annotations are not applicable at this location: {0}\n\
> 
> 
> I don't know whether there are concrete guidelines for this or whether "admissible" is what the JLS uses for this.
> Looking at other annotation-related error messages in this file, most use "applicable" and "not applicable" (one key uses `inapplicable`, but the message still uses `not applicable`).
> There are no other uses of `admissible` in this file.
> There is also `annotation.not.valid.for.type` which uses `annotation not valid for an element of type {0}`, which could be another option.
> 
> Also, not not sure whether it would be `are not applicable *at* this location`, `are not applicable *on* this location`, or something else.

Thanks, I'm very open to changing the language here. I was using 'admissible' because it is used in [JVMS 4.7.20](https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html#jvms-4.7.20) and [JLS 9.7.4](https://docs.oracle.com/javase/specs/jls/se21/html/jls-9.html#jls-9.7.4) to describe where type annotations are allowed on nested types.

> test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out line 1:
> 
>> 1: CantAnnotatePackages.java:14:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), java.lang, @TA java.lang.Object
> 
> In this output, isn't `java.lang` the `1: symbol` and `@TA java.lang.Object` the `2: type` in the error message?
> Won't the `to annotate a qualified type, write {1}.{2}` then output `java.lang. at TA java.lang.Object`, which isn't what we would want.
> Am I parsing this incorrectly?

I think you're parsing the arguments correctly, but when the arguments are formatted for the output the type is printed using its simple name, so we end up with:


test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.java:14: error: type annotations are not admissible at this location: @TA
    @TA java.lang.Object of1;
                 ^
  (to annotate a qualified type, write java.lang. at TA Object)
  ```

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16592#discussion_r1445204346
PR Review Comment: https://git.openjdk.org/jdk/pull/16592#discussion_r1445221432


More information about the compiler-dev mailing list