<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Good question.</p>
<p><br>
</p>
<p>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.</p>
<p><br>
</p>
<p>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).</p>
<p><br>
</p>
<p>Jan</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 10. 01. 25 1:36, Archie Cobbs wrote:<br>
</div>
<blockquote type="cite" cite="mid:CANSoFxujzUE7OEa0=HvPauz2rC-kqGsK_=zweDuUzN3sRgihXQ@mail.gmail.com">
<div dir="ltr">
<div>I have a question about preview and classfile minor
versions.</div>
<div><br>
</div>
<div>In <span style="font-family:monospace">Preview.java</span>
there is this:</div>
<div><br>
<span style="font-family:monospace"> /**<br>
* Report usage of a preview feature. Usages reported
through this method will affect the<br>
* set of sourcefiles with dependencies on preview
features.<br>
* @param pos the position at which the preview feature
was used.<br>
* @param feature the preview feature used.<br>
*/ <br>
public void warnPreview(DiagnosticPosition pos, Feature
feature) {<br>
Assert.check(isEnabled());<br>
Assert.check(isPreview(feature));<br>
if (!lint.isSuppressed(LintCategory.PREVIEW)) {<br>
<span style="background-color:rgb(255,255,0)"><b>sourcesWithPreviewFeatures.add(log.currentSourceFile());</b></span><br>
previewHandler.report(pos, feature.isPlural() ?<br>
LintWarnings.PreviewFeatureUsePlural(feature.nameFragment())
:<br>
LintWarnings.PreviewFeatureUse(feature.nameFragment()));<br>
}<br>
}</span><br>
</div>
<div><br>
</div>
<div>The highlighted line causes the written classfile to have
minor version <span style="font-family:monospace">0xffff</span>,
which triggers a preview warning at runtime.<br>
</div>
<div><br>
</div>
<div>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)?</div>
<div><br>
</div>
<div>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.<br>
</div>
<div><br>
</div>
<div>At least, it seems like <span style="font-family:monospace">--enable-preview</span> would
be a better candidate for controlling the classfile minor
version in this case... or perhaps some new flag.<br>
</div>
<div><br>
</div>
<div>Thanks for any insights.</div>
<div><br>
</div>
<div>-Archie<br>
</div>
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Archie L. Cobbs<br>
</div>
</div>
</blockquote>
</body>
</html>