Integrated: 8369508: Type annotations on anonymous new class creation expressions can't be retrieved

Liam Miller-Cushon cushon at openjdk.org
Wed Oct 29 07:29:12 UTC 2025


On Thu, 9 Oct 2025 14:35:58 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.

This pull request has now been integrated.

Changeset: c97d50d7
Author:    Liam Miller-Cushon <cushon at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/c97d50d793df46292e38707956586dfaa4b77d32
Stats:     32 lines in 3 files changed: 11 ins; 13 del; 8 mod

8369508: Type annotations on anonymous new class creation expressions can't be retrieved

Reviewed-by: vromero

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

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


More information about the compiler-dev mailing list