-
Type:
CSR
-
Resolution: Unresolved
-
Priority:
P3
-
Component/s: core-libs
-
None
-
behavioral
-
low
-
Users are already warned of new constant addition in these classes.
-
Java API
-
SE
Summary
Create a constant, PREVIEW_ENABLED, in java.lang.reflect.ClassFileFormatVersion to represent the set of VM features when preview features are enabled for version-specific queries.
Problem
Many version-specific queries wish to reveal the different behaviors when preview features are enabled. However, these queries should not differ by whether preview features are enabled on the current runtime environment (both preview querying non-preview and non-preview querying preview), and should by default report information that has backward compatibility, which is not fulfilled by preview features.
ClassFileFormatVersion represents a set of VM features associated with a major.minor class file version accepted by a JVM. However, the x.65535 versions are not modeled by a ClassFileFormatVersion.
Solution
Add a PREVIEW_ENABLED constant, a reflective preview API, so that programs (such as tools) running not in preview can examine preview VM features, such as class file structures.
It does not represent a fixed set of features; the features it represents differs from the runtime version. Programs must ensure they are running on the correct Java SE release when they use it.
It returns null for runtimeVersion as it does not have a fixed minimum runtime version.
Specification
--- a/src/java.base/share/classes/java/lang/reflect/ClassFileFormatVersion.java
+++ b/src/java.base/share/classes/java/lang/reflect/ClassFileFormatVersion.java
@@ -25,23 +25,30 @@
/**
- * Class file format versions of the Java virtual machine.
- *
- * See the appropriate edition of <cite>The Java Virtual Machine
- * Specification</cite> for information about a particular class file
- * format version.
- *
- * <p>Note that additional class file format version constants will be
- * added to model future releases of the Java Virtual Machine
- * Specification.
+ * A {@code class} file format version represents a set of VM features, derived
+ * from a supported class {@linkplain ClassFileVersion#majorVersion() major} and
+ * {@linkplain ClassFileVersion#minorVersion() minor} version combination.
+ * The appropriate edition of <cite>The Java Virtual Machine Specification</cite>
+ * for each Java SE release lists its supported major and minor version
+ * combinations and their correspoding format versions.
+ * <p>
+ * Additional class file format version constants will be added to model future
+ * class file formats defined by future releases of the JVMS.
+ * <p>
+ * A special constant, {@link #PREVIEW_ENABLED}, represents the VM features of
+ * the current Java SE release when preview features are enabled.
*
* @apiNote
- * The complete version used in a class file includes a major version
- * and a minor version; this enum only models the major version. A
- * Java virtual machine implementation is required to support a range
- * of major versions; see the corresponding edition of the <cite>The
- * Java Virtual Machine Specification</cite> for details.
+ * A class file format version is derived from a supported class major and minor
+ * version combination. Given a supported combination, the major version alone
+ * is sufficient to identify most class file format versions; see {@link
+ * #fromMajor(int)} and JVMS {@jvms 4.1}.
*
* @since 20
* @see System#getProperties System property {@code java.class.version}
@@ -395,10 +403,32 @@ public enum ClassFileFormatVersion {
* <cite>The Java Virtual Machine Specification, Java SE 27 Edition</cite></a>
*/
RELEASE_27(71),
+ /**
+ * All VM features of the {@linkplain #latest() current Java SE release}
+ * when preview features are enabled. This includes all preview VM features
+ * of the current Java SE release, which may not be supported by later Java
+ * SE releases.
+ *
+ * @apiNote
+ * This is a reflective preview API to allow tools running in Java runtime
+ * environments with no preview feature enabled to examine preview VM
+ * features, such as those present in {@code class} files.
+ * <p>
+ * This constant represents different sets of features on runtimes of
+ * different Java SE releases. Programmers should check the current Java
+ * SE version to ensure they are accessing the desired set of features.
+ *
+ * @since 27
+ * @jls 1.5 Preview Features
+ * @jvms 1.5 Preview Features
+ * @see <a href="https://openjdk.org/jeps/12">
+ * JEP 12: Preview Features</a>
+ */
+ @PreviewFeature(feature = PreviewFeature.Feature.LANGUAGE_MODEL, reflective = true)
+ PREVIEW_ENABLED(ClassFile.latestMajorVersion());
private final int major;
@@ -461,11 +491,14 @@ public static ClassFileFormatVersion valueOf(Runtime.Version rv) {
* runtime version has a {@linkplain Runtime.Version#feature()
* feature} large enough to support this class file format version
* and has no other elements set.
* <p>
* Class file format versions greater than or equal to {@link
- * RELEASE_6} have non-{@code null} results.
+ * #RELEASE_6}, except {@link #PREVIEW_ENABLED}, have
+ * non-{@code null} results.
*/
public Runtime.Version runtimeVersion() {
- csr of
-
JDK-8355536 Model preview enabled VM features in ClassFileFormatVersion
-
- Open
-
- relates to
-
JDK-8289419 Add model of class file versions to core reflection
-
- Closed
-