Is a TYPE_USE annotation stored as such in a class file?

Liam Miller-Cushon cushon at google.com
Thu Feb 16 21:59:32 UTC 2023


I think this is deliberate and covered by
https://docs.oracle.com/javase/specs/jls/se19/html/jls-9.html#jls-9.7.4

A declaration annotation is ... an annotation that applies to a class,
> interface, or type parameter declaration, and whose annotation interface is
> applicable in type contexts


 But I'm not completely sure, and welcome corrections to my reading of the
spec :)

On Thu, Feb 16, 2023 at 1:31 PM Laird Nelson <ljnelson at gmail.com> wrote:

> Another TYPE_USE question. Consider:
>
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ ElementType.TYPE_USE })
> @interface A {}
>
> @A class B{}
>
> I am surprised to see @A in the returned array from
> B.class.getAnnotations() since it is not an element annotation.
>
> Furthermore, I do not see the string "RuntimeVisibleTypeAnnotations" in
> the class file for B (which is why I'm writing to the compiler-dev list). I
> am no VM/bytecode person but I would expect to see that if a
> runtime-visible type use annotation is being recorded, yes? Although I do
> not see a place in the target_info structure that would to my naive eyes be
> suitable for this particular usage.
>
> Is @A's usage here recorded in the wrong place as the wrong sort of
> thing?  This has a whiff of https://bugs.openjdk.org/browse/JDK-8030751
> to it but I wanted to confirm.
>
> Thanks,
> Laird
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20230216/e6ef7c49/attachment.htm>


More information about the compiler-dev mailing list