Question about preview and classfile versions

Archie Cobbs archie.cobbs at gmail.com
Fri Jan 10 00:36:39 UTC 2025


I have a question about preview and classfile minor versions.

In Preview.java there is this:

    /**
     * Report usage of a preview feature. Usages reported through this
method will affect the
     * set of sourcefiles with dependencies on preview features.
     * @param pos the position at which the preview feature was used.
     * @param feature the preview feature used.
     */
    public void warnPreview(DiagnosticPosition pos, Feature feature) {
        Assert.check(isEnabled());
        Assert.check(isPreview(feature));
        if (!lint.isSuppressed(LintCategory.PREVIEW)) {
            *sourcesWithPreviewFeatures.add(log.currentSourceFile());*
            previewHandler.report(pos, feature.isPlural() ?

LintWarnings.PreviewFeatureUsePlural(feature.nameFragment()) :
                    LintWarnings.PreviewFeatureUse(feature.nameFragment()));
        }
    }

The highlighted line causes the written classfile to have minor version
0xffff, which triggers a preview warning at runtime.

That makes sense, but what I don't understand is: Why is that line inside
the IF statement, instead of before it (i.e., always executed)?

It seems (to me) like the behavior of the generated classfile at runtime
should not depend on how you've configured warning suppression at compile
time.

At least, it seems like --enable-preview would be a better candidate for
controlling the classfile minor version in this case... or perhaps some new
flag.

Thanks for any insights.

-Archie

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


More information about the compiler-dev mailing list