RFR: 8207017: Type annotations on anonymous classes in initializer blocks not written to class file
Jan Lahoda
jlahoda at openjdk.org
Tue Feb 14 14:17:52 UTC 2023
On Fri, 10 Feb 2023 22:43:41 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> Javac is not writing type annotations applied to anonymous classes inside of instance or static initializers. Basically for code like:
>
>
> import java.lang.annotation.*;
>
> class X {
>
> @Retention(RetentionPolicy.RUNTIME)
> @Target(ElementType.TYPE_USE)
> public @interface TA {
> String value() default "empty";
> }
>
> {
> class Local {}
> new @TA("LocalInstanceInitializerAnnonymous") Local() {};
> }
>
> static {
> class Local {}
> new @TA("LocalStaticAnnonymous") Local() {};
> }
> }
>
> not type annotations are generated as attributes of methods <init> or <clinit>. This PR is fixing this issue. The annotations are currently generated if the anonymous class is declared inside an instance or static method. The issue is only with initializers,
>
> TIA
Seems sensible.
-------------
Marked as reviewed by jlahoda (Reviewer).
PR: https://git.openjdk.org/jdk/pull/12519
More information about the compiler-dev
mailing list