RFR: 8369508: Type annotations on anonymous new class creation expressions can't be retrieved [v3]

Liam Miller-Cushon cushon at openjdk.org
Tue Oct 28 18:34:15 UTC 2025


> 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:

 - Merge branch 'openjdk:master' into JDK-8369508
 - Reorder an assertion
 - Cleanup
 - 8369508: Type annotations on anonymous new class creation expressions can't be retrieved

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/27730/files
  - new: https://git.openjdk.org/jdk/pull/27730/files/bc796344..fddf385e

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=27730&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27730&range=01-02

  Stats: 60862 lines in 1565 files changed: 36489 ins; 16036 del; 8337 mod
  Patch: https://git.openjdk.org/jdk/pull/27730.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27730/head:pull/27730

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


More information about the compiler-dev mailing list