On Fri, 7 Feb 2025 15:07:26 GMT, Michael Strauß <mstra...@openjdk.org> wrote:

>> modules/javafx.base/src/main/java/com/sun/javafx/PreviewFeature.java line 52:
>> 
>>> 50:     private static final String SUPPRESS_WARNING_PROPERTY = 
>>> "javafx.suppressPreviewBanner";
>>> 51: 
>>> 52:     private static final boolean enabled = 
>>> Boolean.getBoolean(ENABLE_PREVIEW_PROPERTY);
>> 
>> The JDK requires that you opt into preview features _for a specific 
>> version_. That is, rather than a boolean, the JDK uses an integer feature 
>> release value that must match the current release. They do this by using the 
>> `--release` option (in connection with the `--enable-preview`), and 
>> compiling that into the class file, which we can't directly use. Maybe we 
>> can do something similar, though?
>
> This is only done at compilation time, not at runtime. JEP 12 elaborates on 
> this:
> 
>> --enable-preview itself does not take a version number because it would be 
>> easy to misinterpret. For example, on JDK 18, the (hypothetical) flag 
>> --enable-preview 19 would appear to suggest support for the preview features 
>> of JDK 19, but those features are not known at the time of JDK 18's release.

Yeah, that's what I came to realize as well. So our property should remain 
boolean.

The only other thing I could think of is for us to provide a new utility method 
(in some class in javafx.base) that an application must call to register the 
version of JavaFX API that are compiling against. For example, imagine a 
`java.javafx.util.PreviewFeatures` class with the following method:


    public void setVersion(int featureVersion) {}


An application would need to call `PreviewFeatures.setVersion(25)` to use 
JavaFX preview features from JavaFX 25. That method would unlock preview 
features only if the version passed in matches the runtime feature version. 
This would be in addition to the boolean system property.

The question is whether it is worth the additional complexity (not for us to 
implement, that's trivial unless I'm missing something), but rather than 
documentation and burden on the app developer using a preview feature. The docs 
for each new preview feature would need to link to the PreviewFeatures utility 
class to describe how to unlock the features. On the plus side, it would 
provide a common place to document how to unlock preview features -- "call this 
method from the application and set that system property on the command line 
when running the app".

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1359#discussion_r1955043411

Reply via email to