Type annotations on inner type that is an array components

B. Blaser bsrbnd at gmail.com
Wed Jul 25 18:04:29 UTC 2018


Hi,

On 19 July 2018 at 21:23, Alex Buckley <alex.buckley at oracle.com> wrote:
> Hi Werner,
>
> On 7/18/2018 4:49 PM, Werner Dietl wrote:
>>
>> 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;
>> }
>>
>>
>> Compile with javac 8 and 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]
>>
>> Compile with javac 9, 10, or a recent 11 build and ia has the annotation:
>>
>>    ArrayOfInner$Inner[] ia;
>>      descriptor: [LArrayOfInner$Inner;
>>      flags: (0x0000)
>>      RuntimeVisibleTypeAnnotations:
>>        0: #10(#11=I#21): FIELD, location=[ARRAY]
>>
>> Note the missing INNER_TYPE location.
>>
>> I would like to argue that the Java 8 behavior was correct.
>
>
> Sounds right. Given source code that denotes the array type "Inner[]", the
> question is whether the component type of that array type is a nested type
> (ArrayOfInner.Inner) or not (just Inner). Logically, yes, it's a nested
> type, so the target_path item deserves an INNER_TYPE entry.
>
> This feels like the kind of detail we've been round and round on in the
> past. That said, I don't see any mails that would have led to javac changing
> how it emits target_path between 8 and 9. The closest suspect is a
> compiler-dev thread from Jan/Feb 2016 -- "Bug in encoding type annotations
> for supertype_targets" -- which spoke about the target_path being omitted
> entirely for an annotated nested type. (JDK-8148504 was filed against 8, but
> it's still open, so it can't have caused any collateral damage for a field
> type's annotation.)
>
> Alex

Doing some archaeology in 'TypeAnnotations.java' I found a suspect
change-set for JDK-8031744:

https://bugs.openjdk.java.net/browse/JDK-8031744

The array logic has been bundled in 'rewriteArrayType()' but the
following line seems to have disappeared:

http://hg.openjdk.java.net/jdk9/dev/langtools/rev/62e285806e83#l6.440

This change-set might be the culprit but I haven't verified.

Bernard


More information about the compiler-dev mailing list