Question about preview and classfile versions
Jan Lahoda
jan.lahoda at oracle.com
Fri Jan 10 07:49:05 UTC 2025
Good question.
I believe this method is only used for preview language features,
there's a different mechanism for preview API, and warnings for preview
language features cannot be suppressed as per JEP 12. 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. We might want to drop the if altogether, leaving only its body.
Note that if a classfile originates in a source file that does not use
any preview features, it is not marked as preview. That is intentional,
so this cannot be controlled by a global flag (it used to be controlled
by '--enable-preview', and was changed to the per-file handling).
Jan
On 10. 01. 25 1:36, Archie Cobbs wrote:
> 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/20250110/430cbda1/attachment-0001.htm>
More information about the compiler-dev
mailing list