RFR: 8208470: Type annotations on inner type that is an array component [v2]

Jan Lahoda jlahoda at openjdk.org
Tue Feb 14 18:33:43 UTC 2023


On Sat, 11 Feb 2023 23:01:38 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> As stated in the bug great description by Werner D.:
>> 
>> Considering this example:
>> 
>> import java.lang.annotation.ElementType;
>> import java.lang.annotation.Retention;
>> import java.lang.annotation.RetentionPolicy;
>> import java.lang.annotation.Target;
>> 
>> @Retention(RetentionPolicy.RUNTIME)
>> @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
>> @interface TA {
>>   int value();
>> }
>> 
>> class ArrayOfInner {
>>   class Inner {}
>> 
>>   @TA(1) ArrayOfInner. @TA(2) Inner oi;
>>   @TA(3) ArrayOfInner. @TA(4) Inner [] oia;
>>   @TA(5) Inner i;
>>   @TA(6) Inner [] ia;
>> }
>> 
>> If compiled with javac 8, according to javap -v field ia has the annotation:
>> 
>>   ArrayOfInner$Inner[] ia;
>>     descriptor: [LArrayOfInner$Inner;
>>     flags: (0x0000)
>>     RuntimeVisibleTypeAnnotations:
>>       0: #10(#11=I#21): FIELD, location=[ARRAY, INNER_TYPE]
>>         TA(
>>           value=6
>>         )
>> 
>> if compiled with javac > 8 ia has the annotation:
>> 
>>   ArrayOfInner$Inner[] ia;
>>     descriptor: [LArrayOfInner$Inner;
>>     flags: (0x0000)
>>     RuntimeVisibleTypeAnnotations:
>>       0: #10(#11=I#21): FIELD, location=[ARRAY]
>>         TA(
>>           value=6
>>         )
>> 
>> Note the missing `INNER_TYPE` location. This PR is re-establishing the Java 8 behavior.
>> 
>> TIA
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
> 
>   adding bug number to regression test

As I read the patch, it replaces a loop which is supposed to inject the annotation into the deepest type with a recursive call (which then ensures the correct attributes are set). That seems reasonable to me, to the degree I can understand it.

It might be good to try to get Werner's or Michael Ernst's feedback/comment, just to be sure.

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

Marked as reviewed by jlahoda (Reviewer).

PR: https://git.openjdk.org/jdk/pull/12522


More information about the compiler-dev mailing list