Type annotations on inner type that is an array components
Alex Buckley
alex.buckley at oracle.com
Thu Jul 19 19:23:12 UTC 2018
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
More information about the compiler-dev
mailing list