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

Support configuring individual lint categories as errors

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • tools
    • None
    • behavioral
    • low
    • The existing behavior should not change at all, i.e., when only the currently supported command line flags are given.
    • add/remove/modify command line option
    • JDK

      Summary

      Refine the -Werror flag to support lint categories just like -Xlint does. So, for example -Werror:all,-preview would cause an error if any warning other than a preview warning occurred.

      Problem

      -Xlint allows one to customize which warnings should appear and which should be hidden. This caters to different needs in different scenarios - a "one size fits all" approach is too limiting.

      The same logic applies to -Werror: there are scenarios where some warnings are more salient than others to whether a build should fail. Allowing -Werror to function like -Xlint with per-lint category customizations would accomodate this.

      Solution

      First, preserve the existing behavior:

      • If no -Werror flag of any kind appears at all, then no warning will trigger an error.
      • If only the -Werror flag is given, then any warning will trigger an error.

      Next, add support for "custom" flags like -Werror:all, -Werror:none, and -Werror:foo,-bar.

      These flags will be parsed and interpreted exactly like the corresponding -Xlint flags, with one exception: If no -Xlint flag appears at all, then a non-empty set of default lint warning categories is enabled, whereas if no -Werror flag appears at all, then the default behavior is as it is today, namely, no warning will trigger an error (i.e., the default set is empty).

      Note that the existing -Xlint flag has a particular behavior when conflicting flags are combined. For example, -Xlint:all -Xlint:none -Xlint:foo -Xlint:-foo equals -Xlint:all. This same behavior has been preserved and carried over to -Werror.

      Specification

      Here is the diff of the output of the command javac --help && javac --help-extra && javac --help-lint:

      --- x0  2025-02-13 15:32:33.390676169 -0600
      +++ x1  2025-02-13 15:32:57.119988923 -0600
      @@ -56,24 +56,28 @@
               Override location of upgradeable modules
         -verbose                     Output messages about what the compiler is doing
         --version, -version          Version information
      -  -Werror                      Terminate compilation if warnings occur
      +  -Werror                      Terminate compilation if any warnings occur
      +  -Werror:<key>(,<key>)*
      +        Specify warnings that should terminate compilation, separated by comma.
      +        Precede a key by '-' to exclude the specified warning.
      +        Use --help-lint to see the supported keys.
      
         --add-exports <module>/<package>=<other-module>(,<other-module>)*
               Specify a package to be considered as exported from its
      @@ -87,10 +91,10 @@
               Disable support for documentation comments with lines beginning '///'
         -Djava.endorsed.dirs=<dirs>  Override location of endorsed standards path
         -Djava.ext.dirs=<dirs>       Override location of installed extensions
      -  --help-lint                  Print the supported keys for -Xlint
      +  --help-lint                  Print the supported keys for -Xlint and -Werror
         --patch-module <module>=<file>(:<file>)*
               Override or augment a module with classes and resources
               in JAR files or directories
      @@ -134,7 +138,7 @@
         -Xstdout <filename>          Redirect standard output
      
       These extra options are subject to change without notice.
      -The supported keys for -Xlint are:
      +The supported keys for -Xlint and -Werror are:
           all                  Enable all warnings
           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.

            acobbs Archie Cobbs
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: