Question about preview and classfile versions

Archie Cobbs archie.cobbs at gmail.com
Fri Jan 10 15:32:52 UTC 2025


On Fri, Jan 10, 2025 at 1:49 AM Jan Lahoda <jan.lahoda at oracle.com> wrote:

> I And the "lint" here is the "global" Lint instance, that (AFAIK) never
> suppresses anything. I.e. the condition in the "if" statement is always
> true, I believe.
>
The root Lint instance doesn't include any @SuppressWarnings suppressions
but it does include suppressions from command line flags like
-Xlint:-preview, so the "if" statement can be false.

Upon further analysis it appears that this doesn't matter - except in the
case of PREVIEW_REFLECTIVE - because otherwise the code that emits the
warning also explicitly invokes preview.markUsesPreview(pos). See here:
Check.java
<https://github.com/openjdk/jdk/blob/beb0e607d3b66b9e97c263cd8f2e23f447ebfc50/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java#L3827-L3838>
.

So I'm still unsure whether there is a bug. I thought the test below would
trigger that PREVIEW_REFLECTIVE code branch and generate a classfile that
erroneously does NOT have the 0xffff minor version, but it doesn't:

$ cat PreviewTest.java
import java.io.IO;
public class PreviewTest {
    public static void main(String[] args) {
        IO.println("OK");       // preview API
    }
}
$ javac -version
javac 25-internal
$ javac -d classes --enable-preview --release 25 -Xlint:-preview
PreviewTest.java
Note: PreviewTest.java uses preview features of Java SE 25.
Note: Recompile with -Xlint:preview for details.
$ file classes/PreviewTest.class
classes/PreviewTest.class: compiled Java class data, version 69.65535

-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250110/df1fb67c/attachment.htm>


More information about the compiler-dev mailing list