RFR: 8207017: Type annotations on anonymous classes in initializer blocks not written to class file

Vicente Romero vromero at openjdk.org
Tue Feb 14 16:32:08 UTC 2023


On Tue, 14 Feb 2023 14:14:54 GMT, Jan Lahoda <jlahoda 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.

@lahodaj thanks for the review

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

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


More information about the compiler-dev mailing list