RFR: 8369508: Type annotations on anonymous new class creation expressions can't be retrieved [v2]
Liam Miller-Cushon
cushon at openjdk.org
Thu Oct 23 08:30:11 UTC 2025
On Fri, 10 Oct 2025 15:26:29 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:
>> Hi,
>>
>> Please consider this fix for [JDK-8369508: Type annotations on anonymous new class creation expressions can't be retrieved](https://bugs.openjdk.org/browse/JDK-8369508).
>>
>> When visiting a type annotation on an anonymous class instantiation expression, javac currently skips attribution of the annotated type when visiting it as part of the `new` expression, to prevent them from being incorrectly attached to the enclosing method instead of the synthetic declaration of the anonymous class (see [JDK-8198945](https://bugs.openjdk.org/browse/JDK-8198945)). However because this logic happens early, and results in skipping attribution of these annotations, they aren't available on the type model elements for the new class creation expression, which means they can't be retrieved by clients of the compiler tree API.
>>
>> This fix shifts the handling of these annotations later, to allow them to get attributed, but then to still prevent them from being attached to the enclosing method symbol of the anonymous class declaration.
>
> Liam Miller-Cushon has updated the pull request incrementally with one additional commit since the last revision:
>
> Reorder an assertion
Hi, is there any feedback on this change?
I did some of the related previous fixes in this area (JDK-8198945, JDK-8351431) and think is more robust than the current behaviour. It was tested with some tooling that uses the affected javac APIs to process type annotations, and it resolved the issues that were being seen with type annotations in new class creation expressions.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27730#issuecomment-3435720926
More information about the compiler-dev
mailing list