JDK-8356111 : Create version constants to model preview language and vm features
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P3
  • Status: Draft
  • Resolution: Unresolved
  • Fix Versions: tbd
  • Submitted: 2025-05-03
  • Updated: 2025-08-14
Related Reports
CSR :  
Description
Summary
-------

Create new constants, `CURRENT_PREVIEW`, in `javax.lang.model.SourceVersion` and `java.lang.reflect.ClassFileFormatVersion` to represent preview features 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.

Solution
--------

Add a `CURRENT_PREVIEW` constant to both classes, with the following properties:

1. It behaves as if it is an arbitrary future version to the release the program is compiled against, like any other additional constant a program will encounter when running on a JRE of later Java SE releases.
2. It is not subject to backward compatibility in future versions. This is revealed by a new API, `boolean isSupported()`.
3. It is a reflective preview API, so that programs (such as tools) running not in preview can use it; but programs must ensure they are running on the correct Java SE release when they use it.

There are additional changes to support this evolution.

1. A new API is added to determine if a version is subject to backward compatibility. Only the `CURRENT_PREVIEW` is not subject to backward compatibility. This API is not preview.

        boolean isSupported()

2. `ClassFileFormatVersion` sees some relevant specification cleanup that better describes its situations. For example, a later release can loosen restrictions that make a seemingly compatible CFFV class no longer runnable on a previous Java SE release.

Specification
-------------

See attachment.
Comments
Pre-review comment: the preview visitors (see JDK-8329624/CSR JDK-8329634) would also need to be incorporated into a proposal in this area. The "obvious" update may suffice, but that would have to be validated.
05-05-2025