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

Liam Miller-Cushon cushon at openjdk.org
Fri Mar 7 17:30:10 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.

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

Commit messages:
 - 8351431: Type annotations on new class creation expressions can't be retrieved

Changes: https://git.openjdk.org/jdk/pull/23946/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23946&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8351431
  Stats: 160 lines in 3 files changed: 153 ins; 1 del; 6 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