8352612: No way to add back lint categories after "none"

Reviewed-by: mcimadamore
This commit is contained in:
Archie Cobbs 2025-05-05 20:40:45 +00:00
parent 620f81671a
commit ca7e4c4e05
11 changed files with 50 additions and 35 deletions

View File

@ -146,13 +146,7 @@ public enum Option {
}
},
// -nowarn is retained for command-line backward compatibility
NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC) {
@Override
public void process(OptionHelper helper, String option) {
helper.put("-Xlint:none", option);
}
},
NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC),
VERBOSE("-verbose", "opt.verbose", STANDARD, BASIC),

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,7 @@ javac.opt.g.none=\
javac.opt.g.lines.vars.source=\
Generate only some debugging info
javac.opt.nowarn=\
Generate no warnings
Generate only mandatory warnings
javac.opt.verbose=\
Output messages about what the compiler is doing
javac.opt.deprecation=\
@ -168,16 +168,16 @@ javac.opt.Xbootclasspath.p=\
javac.opt.Xbootclasspath.a=\
Append to the bootstrap class path
javac.opt.Xlint=\
Enable recommended warnings
Enable recommended warning categories
javac.opt.Xlint.all=\
Enable all warnings
Enable all warning categories
javac.opt.Xlint.none=\
Disable all warnings
Disable all warning categories
#L10N: do not localize: -Xlint
javac.opt.arg.Xlint=\
<key>(,<key>)*
javac.opt.Xlint.custom=\
Warnings to enable or disable, separated by comma.\n\
Warning categories to enable or disable, separated by comma.\n\
Precede a key by ''-'' to disable the specified warning.\n\
Use --help-lint to see the supported keys.
javac.opt.Xlint.desc.auxiliaryclass=\

View File

@ -360,7 +360,7 @@ public class Log extends AbstractLog {
private void initOptions(Options options) {
this.dumpOnError = options.isSet(DOE);
this.promptOnError = options.isSet(PROMPT);
this.emitWarnings = options.isUnset(XLINT_CUSTOM, "none");
this.emitWarnings = options.isUnset(NOWARN);
this.suppressNotes = options.isSet("suppressNotes");
this.MaxErrors = getIntOption(options, XMAXERRS, getDefaultMaxErrors());
this.MaxWarnings = getIntOption(options, XMAXWARNS, getDefaultMaxWarnings());

View File

@ -325,8 +325,7 @@ file system locations may be directories, JAR files or JMOD files.
: Specifies the version of modules that are being compiled.
<a id="option-nowarn">`-nowarn`</a>
: Disables warning messages. This option operates the same as the
`-Xlint:none` option.
: Generate only mandatory warnings.
<a id="option-parameters">`-parameters`</a>
: Generates metadata for reflection on method parameters. Stores formal
@ -562,12 +561,14 @@ file system locations may be directories, JAR files or JMOD files.
warnings is recommended.
<a id="option-Xlint-custom">`-Xlint:`\[`-`\]*key*(`,`\[`-`\]*key*)\*</a>
: Supplies warnings to enable or disable, separated by comma. Precede a key
by a hyphen (`-`) to disable the specified warning.
: Enables and/or disables warning categories using the one or more of the keys described
below separated by commas. The keys `all` and `none` enable or disable all categories
(respectively); other keys enable the corresponding category, or disable it if preceded
by a hyphen (`-`).
Supported values for *key* are:
- `all`: Enables all warnings.
- `all`: Enables all warning categories.
- `auxiliaryclass`: Warns about an auxiliary class that is hidden in a
source file, and is used from other files.
@ -659,7 +660,7 @@ file system locations may be directories, JAR files or JMOD files.
- `varargs`: Warns about the potentially unsafe `vararg` methods.
- `none`: Disables all warnings.
- `none`: Disables all warning categories.
With the exception of `all` and `none`, the keys can be used with
the `@SuppressWarnings` annotation to suppress warnings in a part

View File

@ -1,15 +1,20 @@
/**
* @test /nodynamiccopyright/
* @bug 6183484
* @summary verify -nowarn is the same as -Xlint:none
* @compile/ref=NoWarn1.out -XDrawDiagnostics NoWarn.java
* @compile/ref=NoWarn2.out -XDrawDiagnostics -nowarn NoWarn.java
* @compile/ref=NoWarn2.out -XDrawDiagnostics -Xlint:none NoWarn.java
* @test /nodynamiccopyright/
* @bug 6183484 8352612
* @summary Restrict -Xlint:none to affect only lint categories, while -nowarn disables all warnings
* @compile/ref=NoWarn1.out -XDfind=diamond -XDrawDiagnostics -Xlint:none NoWarn.java
* @compile/ref=NoWarn2.out -XDfind=diamond -XDrawDiagnostics -Xlint:divzero,unchecked NoWarn.java
* @compile/ref=NoWarn2.out -XDfind=diamond -XDrawDiagnostics -Xlint:none,divzero,unchecked NoWarn.java
* @compile/ref=NoWarn3.out -XDfind=diamond -XDrawDiagnostics -Xlint:none -nowarn NoWarn.java
* @compile/ref=NoWarn4.out -XDfind=diamond -XDrawDiagnostics -Xlint:divzero,unchecked -nowarn NoWarn.java
* @compile/ref=NoWarn4.out -XDfind=diamond -XDrawDiagnostics -Xlint:none,divzero,unchecked -nowarn NoWarn.java
*/
import java.util.*;
class NoWarn {
void m(Object... args) { }
void foo() {
m(null);
}
Set<?> z = null; // Mandatory Lint Lint Category How can it be suppressed?
// --------- ---- ------------- -------------------------
sun.misc.Unsafe b; // Yes No N/A Not possible
Set<String> a = new HashSet<String>(); // No No N/A "-nowarn" only (requires -XDfind=diamond)
Set<String> d = (Set<String>)z; // Yes Yes "unchecked" "-Xlint:-unchecked" only
int c = 1/0; // No Yes "divzero" "-Xlint:-divzero" or "-nowarn"
}

View File

@ -1,2 +1,5 @@
NoWarn.java:13:11: compiler.warn.inexact.non-varargs.call: java.lang.Object, java.lang.Object[]
1 warning
NoWarn.java:16:13: compiler.warn.sun.proprietary: sun.misc.Unsafe
NoWarn.java:17:32: compiler.warn.diamond.redundant.args
- compiler.note.unchecked.filename: NoWarn.java
- compiler.note.unchecked.recompile
2 warnings

View File

@ -0,0 +1,5 @@
NoWarn.java:16:13: compiler.warn.sun.proprietary: sun.misc.Unsafe
NoWarn.java:18:34: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.util.Set<compiler.misc.type.captureof: 1, ?>, java.util.Set<java.lang.String>
NoWarn.java:19:15: compiler.warn.div.zero
NoWarn.java:17:32: compiler.warn.diamond.redundant.args
4 warnings

View File

@ -0,0 +1,4 @@
NoWarn.java:16:13: compiler.warn.sun.proprietary: sun.misc.Unsafe
- compiler.note.unchecked.filename: NoWarn.java
- compiler.note.unchecked.recompile
1 warning

View File

@ -0,0 +1,3 @@
NoWarn.java:16:13: compiler.warn.sun.proprietary: sun.misc.Unsafe
NoWarn.java:18:34: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.util.Set<compiler.misc.type.captureof: 1, ?>, java.util.Set<java.lang.String>
2 warnings

View File

@ -6,7 +6,7 @@
*
* @compile Warn1.java
* @compile/ref=Warn1.out -XDrawDiagnostics Warn1.java
* @compile -Werror -Xlint:none Warn1.java
* @compile -Werror -nowarn Warn1.java
*/
package varargs.warn1;

View File

@ -6,7 +6,7 @@
*
* @compile Warn2.java
* @compile/fail/ref=Warn2.out -XDrawDiagnostics -Werror Warn2.java
* @compile -Werror -Xlint:none Warn2.java
* @compile -Werror -nowarn Warn2.java
*/
package varargs.warn2;