Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8352901

No way to add back lint categories after "none"

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • tools
    • None
    • binary
    • medium
    • Since `-Xlint:none` and `-nowarn` are currently synonyms, anyone building with `-Xlint:none` when what they actually want is `-nowarn`, or vice-versa, can start to see builds fail until they use the correct flag.
    • add/remove/modify command line option
    • JDK

      Summary

      Change the behavior of -Xlint:none so that it simply disables all lint categories, instead of disabling all lint categories and applying -nowarn.

      Problem

      One would expect that the -Xlint:none flag would simply disable all lint categories, which would be consistent with how -Xlint:all simply enables all lint categories, and just as -Xlint:all,-serial would enable all lint cagegores except serial, that -Xlint:none,serial would disable all lint categories except serial.

      Unfortunately, -Xlint:none has an extra, hidden side-effect, which is to effectively apply the -nowarn flag: in addition to disabling all int categories, it also disables all non-mandatory warnings, period. So for example, trying to do -Xlint:none,serial to enable only the serial lint category is futile: the category will be enabled but the warnings will never appear.

      Back in 2004, the equivalence between -Xlint:none and -nowarn was made explicit by JDK-6183484, which claims "The javac documentation specifies that the effect of the -nowarn option is the same as specifying -Xlint:none."

      That assumption that "lint" and "warning" mean the same thing is no longer true. Some warnings are lint warnings, i.e., they are associated with some lint category which can be enabled or suppressed, and some warnings are not lint warnings.

      Furthermore, some warnings are mandatory warnings, and some warnings are not mandatory warnings. The -nowarn flag does not disable mandatory warnings, so -Xlint:none and -nowarn are actually incompatible in two different dimensions: for example, -nowarn does not disable the "unchecked" lint warning (because it's a mandatory warning), whereas -Xlint:-unchecked does.

      Solution

      The proposal is:

      • Remove the hidden side-effect in which -Xlint:none implies -nowarn
      • Update the javac help output more accurately reflect reality

      Outstanding question: Should we conditionalize this change on -source 25 or greater? Is it even appropriate for -source to be used to control the behavior of command line flags?

      Specification

      Here is a diff of the output of the following command before & after this change:

      $ javac --help && javac --help-extra && javac --help-lint

      Diff:

      --- x0  2025-03-25 10:06:47.267241245 -0600
      +++ x1  2025-03-25 10:06:57.732617571 -0600
      @@ -38,7 +38,7 @@
               Specify where to find input source files for multiple modules
         --module-version <version>
               Specify version of modules that are being compiled
      -  -nowarn                      Generate no warnings
      +  -nowarn                      Generate only mandatory warnings
         -parameters
               Generate metadata for reflection on method parameters
         -proc:{none,only,full}
      @@ -110,9 +110,9 @@
               a qualified package name or a package name prefix followed by '.*',
               which expands to all sub-packages of the given package. Each <package>
               can be prefixed with '-' to disable checks for the specified package(s).
      -  -Xlint                       Enable recommended warnings
      +  -Xlint                       Enable recommended lint warning categories
         -Xlint:<key>(,<key>)*
      -        Warnings to enable or disable, separated by comma.
      +        Lint warning categories to enable or disable, separated by comma.
               Precede a key by '-' to disable the specified warning.
               Use --help-lint to see the supported keys.
         -Xmaxerrs <number>           Set the maximum number of errors to print
      @@ -135,7 +135,7 @@
      
       These extra options are subject to change without notice.
       The supported keys for -Xlint are:
      -    all                  Enable all warnings
      +    all                  Enable all lint warning categories
           auxiliaryclass       Warn about an auxiliary class that is hidden in a source file, and is used from other files.
           cast                 Warn about use of unnecessary casts.
           classfile            Warn about issues related to classfile contents.
      @@ -176,4 +176,4 @@
           varargs              Warn about potentially unsafe vararg methods.
           preview              Warn about use of preview language features.
           restricted           Warn about use of restricted methods.
      -    none                 Disable all warnings
      +    none                 Disable all lint warning categories

            acobbs Archie Cobbs
            acobbs Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: