On Tue, 30 Jun 2026 19:21:35 GMT, Jan Lahoda <[email protected]> wrote:

>> Consider source files like this:
>> 
>> $ cat /tmp/ValueClass.java 
>> value class ValueClass {}
>> $ cat /tmp/TestValue.java 
>> public class TestValue {
>>     ValueClass c;
>> }
>> 
>> 
>> When compiled like this:
>> 
>> $ javac --enable-preview --release 28 -Xlint:preview /tmp/ValueClass.java 
>> /tmp/ValueClass.java:1: warning: [preview] value classes are a preview 
>> feature and may be removed in a future release.
>> value class ValueClass {}
>> ^
>> 1 warning
>> $ javac --enable-preview --release 28 -Xlint:preview -classpath /tmp 
>> /tmp/TestValue.java 
>> warning: [preview] class file for /tmp/ValueClass.class uses preview 
>> features of Java SE 28.
>> 1 warning
>> 
>> 
>> Note that while the `TestValue.class` is marked as preview, there's no 
>> warning on the use of `ValueClass`. This is not aligned with the JEP 12 
>> wording:
>> 
>>> When compiling with preview features enabled, any source code reference to 
>>> (i) a class or interface declared using a preview language feature, ..., 
>>> causes a preview warning.
>> 
>> Currently javac marks the classfile preview using an explicit test in the 
>> `ClassWriter`, but that does not seem quite right. This PR proposes to mark 
>> value classes as `Preview.declaredUsingPreviewFeature == true`, which should 
>> automatically produce a warning, and mark the appropriate classfile as 
>> preview.
>> 
>> For the example above:
>> 
>> $ javac --enable-preview --release 28 -Xlint:preview -classpath /tmp 
>> /tmp/TestValue.java 
>> warning: [preview] class file for /tmp/ValueClass.class uses preview 
>> features of Java SE 28.
>> /tmp/TestValue.java:2: warning: [preview] class ValueClass is declared using 
>> a preview feature, which may be removed in a future release.
>>     ValueClass c;
>>     ^
>> 2 warnings
>> 
>> 
>> Note this will also report the warning for `Integer`, when preview is 
>> enabled:
>> 
>> $ cat /tmp/Test.java 
>> public class Test {
>>     Integer i;
>> }
>> $ javac /tmp/Test.java
>> $ javac --enable-preview --release 28 -Xlint:preview /tmp/Test.java
>> warning: [preview] class file for /@/java.base/java/lang/Integer.sig uses 
>> preview features of Java SE 28.
>> /tmp/Test.java:2: warning: [preview] class Integer is declared using a 
>> preview feature, which may be removed in a future release.
>>     Integer i;
>>     ^
>> 2 warnings
>> 
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Jan Lahoda has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Adjusting tests to the recent change.

@lahodaj 
Your change (at version 988c4b51478ccce1db7b585a100b339b4864e483) is now ready 
to be sponsored by a Committer.

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

PR Comment: https://git.openjdk.org/valhalla/pull/2601#issuecomment-4857381802

Reply via email to