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 and man page to more accurately reflect reality

      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-04-11 08:16:11.265557655 -0500
      +++ x1  2025-04-11 08:16:15.358947301 -0500
      @@ -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 warning categories
         -Xlint:<key>(,<key>)*
      -        Warnings to enable or disable, separated by comma.
      +        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 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 warning categories

      Here is a diff of the generated man page before & after this change:

          --- m0  2025-04-11 08:16:52.824231312 -0500
          +++ m1  2025-04-11 08:17:08.500495306 -0500
          @@ -301,8 +301,7 @@
                         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
          @@ -549,12 +548,15 @@
                         available 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 preced‐
          +              ed 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.
          @@ -654,7 +656,7 @@
      
                         • 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

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

              Created:
              Updated: