From 188da51f30e5ca3945fee91fe2e94f0466151c06 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Thu, 6 Nov 2025 04:42:20 +0000 Subject: [PATCH] 8365699: Remove jdk.internal.javac.PreviewFeature.Feature enum values for features finalized in Java 25 or earlier Reviewed-by: vromero, liach --- .../jdk/internal/javac/PreviewFeature.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java b/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java index e6c994a12b1..eb0346c7397 100644 --- a/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java +++ b/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java @@ -64,18 +64,27 @@ public @interface PreviewFeature { * Values should be annotated with the feature's {@code JEP}. */ public enum Feature { - // while building the interim javac, the ClassReader will produce a warning when loading a class - // keeping the constant of a feature that has been integrated or dropped, serves the purpose of muting such warnings. + // The JDK build process involves creating an interim javac which is then + // used to compile the rest of the JDK. The jdk.internal.javac.PreviewFeature + // annotation from the current sources is used when compiling interim javac. + // That's because the javac APIs of the current sources may be annotated with + // this annotation and they may be using the enum constants of the current sources. + // Furthermore, when compiling interim javac, the class files from the bootstrap JDK get + // used and those may also contain the PreviewFeature annotation. However, they may be + // using the enum constants of the bootstrap JDK's PreviewFeature annotation. + // If javac sees an annotation with an unknown enum constant, it produces a warning, + // and that in turn fails the build. + // So, in the current sources, we need to preserve the PreviewFeature enum constants + // for as long as the interim javac build needs it. As a result, we retain PreviewFeature + // enum constants for preview features that are present in the bootstrap JDK. + // Older constants can be removed. + // + // For example, Class-File API became final in JDK 24. As soon as JDK 23 was dropped as + // the bootstrap JDK, the CLASSFILE_API enum constant became eligible for removal. //--- - IMPLICIT_CLASSES, //to be removed when boot JDK is 25 - SCOPED_VALUES, @JEP(number=505, title="Structured Concurrency", status="Fifth Preview") STRUCTURED_CONCURRENCY, - CLASSFILE_API, - STREAM_GATHERERS, - MODULE_IMPORTS, //remove when the boot JDK is JDK 25 - KEY_DERIVATION, //remove when the boot JDK is JDK 25 @JEP(number = 502, title = "Stable Values", status = "Preview") STABLE_VALUES, @JEP(number=470, title="PEM Encodings of Cryptographic Objects", status="Preview")