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

Vicente Romero vromero at openjdk.org
Wed Apr 2 17:11:52 UTC 2025


On Fri, 7 Mar 2025 17:26:25 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

> 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.

lgtm

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/23946#pullrequestreview-2737011829


More information about the compiler-dev mailing list