diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java index 44d90a7e59b..e0fdd30c242 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java @@ -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), diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties index 28a89ee3072..1a8be506e7f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties @@ -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=\ (,)* 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=\ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java index ec74c860e0a..fd51729bf21 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java @@ -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()); diff --git a/src/jdk.compiler/share/man/javac.md b/src/jdk.compiler/share/man/javac.md index 3edbeda6eca..f951ea0def3 100644 --- a/src/jdk.compiler/share/man/javac.md +++ b/src/jdk.compiler/share/man/javac.md @@ -325,8 +325,7 @@ file system locations may be directories, JAR files or JMOD files. : Specifies the version of modules that are being compiled. `-nowarn` -: Disables warning messages. This option operates the same as the - `-Xlint:none` option. +: Generate only mandatory warnings. `-parameters` : 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. `-Xlint:`\[`-`\]*key*(`,`\[`-`\]*key*)\* -: 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 diff --git a/test/langtools/tools/javac/lint/NoWarn.java b/test/langtools/tools/javac/lint/NoWarn.java index 7d6153807f2..4a1b99a7bed 100644 --- a/test/langtools/tools/javac/lint/NoWarn.java +++ b/test/langtools/tools/javac/lint/NoWarn.java @@ -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 a = new HashSet(); // No No N/A "-nowarn" only (requires -XDfind=diamond) + Set d = (Set)z; // Yes Yes "unchecked" "-Xlint:-unchecked" only + int c = 1/0; // No Yes "divzero" "-Xlint:-divzero" or "-nowarn" } diff --git a/test/langtools/tools/javac/lint/NoWarn1.out b/test/langtools/tools/javac/lint/NoWarn1.out index c4a8456889f..5fea0f7b51a 100644 --- a/test/langtools/tools/javac/lint/NoWarn1.out +++ b/test/langtools/tools/javac/lint/NoWarn1.out @@ -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 diff --git a/test/langtools/tools/javac/lint/NoWarn2.out b/test/langtools/tools/javac/lint/NoWarn2.out index e69de29bb2d..d33c2404e1e 100644 --- a/test/langtools/tools/javac/lint/NoWarn2.out +++ b/test/langtools/tools/javac/lint/NoWarn2.out @@ -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, java.util.Set +NoWarn.java:19:15: compiler.warn.div.zero +NoWarn.java:17:32: compiler.warn.diamond.redundant.args +4 warnings diff --git a/test/langtools/tools/javac/lint/NoWarn3.out b/test/langtools/tools/javac/lint/NoWarn3.out new file mode 100644 index 00000000000..9491fe8b9ee --- /dev/null +++ b/test/langtools/tools/javac/lint/NoWarn3.out @@ -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 diff --git a/test/langtools/tools/javac/lint/NoWarn4.out b/test/langtools/tools/javac/lint/NoWarn4.out new file mode 100644 index 00000000000..6586ff995bf --- /dev/null +++ b/test/langtools/tools/javac/lint/NoWarn4.out @@ -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, java.util.Set +2 warnings diff --git a/test/langtools/tools/javac/varargs/Warn1.java b/test/langtools/tools/javac/varargs/Warn1.java index eb5758d9a23..f65c2f9bc73 100644 --- a/test/langtools/tools/javac/varargs/Warn1.java +++ b/test/langtools/tools/javac/varargs/Warn1.java @@ -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; diff --git a/test/langtools/tools/javac/varargs/Warn2.java b/test/langtools/tools/javac/varargs/Warn2.java index 9ba8b8f8832..6d411f31f57 100644 --- a/test/langtools/tools/javac/varargs/Warn2.java +++ b/test/langtools/tools/javac/varargs/Warn2.java @@ -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;