RFR: 8351431: Type annotations on new class creation expressions can't be retrieved [v2]

Liam Miller-Cushon cushon at openjdk.org
Wed Apr 2 17:37:11 UTC 2025


> Hello,
> 
> Please consider this fix for [JDK-8351431](https://bugs.openjdk.org/browse/JDK-8351431), which allows type annotations on the class type of a `new` class creation expression to be retrieved by the Compiler Tree API.
> 
> Currently `Attr` is skipping `annotateTypeSecondStage` for all new class types, but the special case only needs to be applied to anonymous new class creation expressions to be consistent with logic in `Annotate`:
> 
> https://github.com/openjdk/jdk/blob/7c22b814d670deda6c2bb93b1e150975c27a165f/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java#L1162-L1166
> 
> This also removes a check of `isNewClass` (now `isNewAnonymousClass`) in `InvalidCanonicalConstructorInRecord`, because the field was only set before descending into a `JCNewClass.clazz`, which can't contain return statements.

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 two additional commits since the last revision:

 - Merge remote-tracking branch 'origin/master' into JDK-8351431
 - 8351431: Type annotations on new class creation expressions can't be retrieved

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/23946/files
  - new: https://git.openjdk.org/jdk/pull/23946/files/84d34fd2..f604a9f7

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

  Stats: 123852 lines in 2674 files changed: 49008 ins; 58144 del; 16700 mod
  Patch: https://git.openjdk.org/jdk/pull/23946.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/23946/head:pull/23946

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


More information about the compiler-dev mailing list