Skip to content

Commit ca7e4c4

Browse files
committed
8352612: No way to add back lint categories after "none"
Reviewed-by: mcimadamore
1 parent 620f816 commit ca7e4c4

File tree

11 files changed

+50
-35
lines changed

11 files changed

+50
-35
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,7 @@ public void process(OptionHelper helper, String option, String arg) {
146146
}
147147
},
148148

149-
// -nowarn is retained for command-line backward compatibility
150-
NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC) {
151-
@Override
152-
public void process(OptionHelper helper, String option) {
153-
helper.put("-Xlint:none", option);
154-
}
155-
},
149+
NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC),
156150

157151
VERBOSE("-verbose", "opt.verbose", STANDARD, BASIC),
158152

src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -36,7 +36,7 @@ javac.opt.g.none=\
3636
javac.opt.g.lines.vars.source=\
3737
Generate only some debugging info
3838
javac.opt.nowarn=\
39-
Generate no warnings
39+
Generate only mandatory warnings
4040
javac.opt.verbose=\
4141
Output messages about what the compiler is doing
4242
javac.opt.deprecation=\
@@ -168,16 +168,16 @@ javac.opt.Xbootclasspath.p=\
168168
javac.opt.Xbootclasspath.a=\
169169
Append to the bootstrap class path
170170
javac.opt.Xlint=\
171-
Enable recommended warnings
171+
Enable recommended warning categories
172172
javac.opt.Xlint.all=\
173-
Enable all warnings
173+
Enable all warning categories
174174
javac.opt.Xlint.none=\
175-
Disable all warnings
175+
Disable all warning categories
176176
#L10N: do not localize: -Xlint
177177
javac.opt.arg.Xlint=\
178178
<key>(,<key>)*
179179
javac.opt.Xlint.custom=\
180-
Warnings to enable or disable, separated by comma.\n\
180+
Warning categories to enable or disable, separated by comma.\n\
181181
Precede a key by ''-'' to disable the specified warning.\n\
182182
Use --help-lint to see the supported keys.
183183
javac.opt.Xlint.desc.auxiliaryclass=\

src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private Log(Context context, Map<WriterKind, PrintWriter> writers) {
360360
private void initOptions(Options options) {
361361
this.dumpOnError = options.isSet(DOE);
362362
this.promptOnError = options.isSet(PROMPT);
363-
this.emitWarnings = options.isUnset(XLINT_CUSTOM, "none");
363+
this.emitWarnings = options.isUnset(NOWARN);
364364
this.suppressNotes = options.isSet("suppressNotes");
365365
this.MaxErrors = getIntOption(options, XMAXERRS, getDefaultMaxErrors());
366366
this.MaxWarnings = getIntOption(options, XMAXWARNS, getDefaultMaxWarnings());

src/jdk.compiler/share/man/javac.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ file system locations may be directories, JAR files or JMOD files.
325325
: Specifies the version of modules that are being compiled.
326326

327327
<a id="option-nowarn">`-nowarn`</a>
328-
: Disables warning messages. This option operates the same as the
329-
`-Xlint:none` option.
328+
: Generate only mandatory warnings.
330329

331330
<a id="option-parameters">`-parameters`</a>
332331
: Generates metadata for reflection on method parameters. Stores formal
@@ -562,12 +561,14 @@ file system locations may be directories, JAR files or JMOD files.
562561
warnings is recommended.
563562

564563
<a id="option-Xlint-custom">`-Xlint:`\[`-`\]*key*(`,`\[`-`\]*key*)\*</a>
565-
: Supplies warnings to enable or disable, separated by comma. Precede a key
566-
by a hyphen (`-`) to disable the specified warning.
564+
: Enables and/or disables warning categories using the one or more of the keys described
565+
below separated by commas. The keys `all` and `none` enable or disable all categories
566+
(respectively); other keys enable the corresponding category, or disable it if preceded
567+
by a hyphen (`-`).
567568

568569
Supported values for *key* are:
569570

570-
- `all`: Enables all warnings.
571+
- `all`: Enables all warning categories.
571572

572573
- `auxiliaryclass`: Warns about an auxiliary class that is hidden in a
573574
source file, and is used from other files.
@@ -659,7 +660,7 @@ file system locations may be directories, JAR files or JMOD files.
659660

660661
- `varargs`: Warns about the potentially unsafe `vararg` methods.
661662

662-
- `none`: Disables all warnings.
663+
- `none`: Disables all warning categories.
663664

664665
With the exception of `all` and `none`, the keys can be used with
665666
the `@SuppressWarnings` annotation to suppress warnings in a part
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
/**
2-
* @test /nodynamiccopyright/
3-
* @bug 6183484
4-
* @summary verify -nowarn is the same as -Xlint:none
5-
* @compile/ref=NoWarn1.out -XDrawDiagnostics NoWarn.java
6-
* @compile/ref=NoWarn2.out -XDrawDiagnostics -nowarn NoWarn.java
7-
* @compile/ref=NoWarn2.out -XDrawDiagnostics -Xlint:none NoWarn.java
2+
* @test /nodynamiccopyright/
3+
* @bug 6183484 8352612
4+
* @summary Restrict -Xlint:none to affect only lint categories, while -nowarn disables all warnings
5+
* @compile/ref=NoWarn1.out -XDfind=diamond -XDrawDiagnostics -Xlint:none NoWarn.java
6+
* @compile/ref=NoWarn2.out -XDfind=diamond -XDrawDiagnostics -Xlint:divzero,unchecked NoWarn.java
7+
* @compile/ref=NoWarn2.out -XDfind=diamond -XDrawDiagnostics -Xlint:none,divzero,unchecked NoWarn.java
8+
* @compile/ref=NoWarn3.out -XDfind=diamond -XDrawDiagnostics -Xlint:none -nowarn NoWarn.java
9+
* @compile/ref=NoWarn4.out -XDfind=diamond -XDrawDiagnostics -Xlint:divzero,unchecked -nowarn NoWarn.java
10+
* @compile/ref=NoWarn4.out -XDfind=diamond -XDrawDiagnostics -Xlint:none,divzero,unchecked -nowarn NoWarn.java
811
*/
9-
12+
import java.util.*;
1013
class NoWarn {
11-
void m(Object... args) { }
12-
void foo() {
13-
m(null);
14-
}
14+
Set<?> z = null; // Mandatory Lint Lint Category How can it be suppressed?
15+
// --------- ---- ------------- -------------------------
16+
sun.misc.Unsafe b; // Yes No N/A Not possible
17+
Set<String> a = new HashSet<String>(); // No No N/A "-nowarn" only (requires -XDfind=diamond)
18+
Set<String> d = (Set<String>)z; // Yes Yes "unchecked" "-Xlint:-unchecked" only
19+
int c = 1/0; // No Yes "divzero" "-Xlint:-divzero" or "-nowarn"
1520
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
NoWarn.java:13:11: compiler.warn.inexact.non-varargs.call: java.lang.Object, java.lang.Object[]
2-
1 warning
1+
NoWarn.java:16:13: compiler.warn.sun.proprietary: sun.misc.Unsafe
2+
NoWarn.java:17:32: compiler.warn.diamond.redundant.args
3+
- compiler.note.unchecked.filename: NoWarn.java
4+
- compiler.note.unchecked.recompile
5+
2 warnings
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NoWarn.java:16:13: compiler.warn.sun.proprietary: sun.misc.Unsafe
2+
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>
3+
NoWarn.java:19:15: compiler.warn.div.zero
4+
NoWarn.java:17:32: compiler.warn.diamond.redundant.args
5+
4 warnings
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
NoWarn.java:16:13: compiler.warn.sun.proprietary: sun.misc.Unsafe
2+
- compiler.note.unchecked.filename: NoWarn.java
3+
- compiler.note.unchecked.recompile
4+
1 warning
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NoWarn.java:16:13: compiler.warn.sun.proprietary: sun.misc.Unsafe
2+
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>
3+
2 warnings

test/langtools/tools/javac/varargs/Warn1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @compile Warn1.java
88
* @compile/ref=Warn1.out -XDrawDiagnostics Warn1.java
9-
* @compile -Werror -Xlint:none Warn1.java
9+
* @compile -Werror -nowarn Warn1.java
1010
*/
1111

1212
package varargs.warn1;

0 commit comments

Comments
 (0)