RFR: 8334161: Enable -Werror for javac tasks to fail on any warnings
Ambarish Rapte
arapte at openjdk.org
Wed Jun 26 18:19:17 UTC 2024
On Wed, 12 Jun 2024 21:57:32 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:
> This PR is a follow-on to #1474.
>
> Enable `javac -Werror` so that javac warnings, including but not limited to javac lint warnings, will cause the build to fail. As with the fix for [JDK-8327255](https://bugs.openjdk.org/browse/JDK-8327255), we define three new properties to enable `-Werror`, one for each type of java compilation task: sdk classes, test classes (including shims), and tool classes (including JSLC). The defaults for `-Werror` for these three groups are:
>
> * `JAVAC_WERROR` : `true`
> * `TOOL_JAVAC_WERROR` : `false`
> * `TEST_JAVAC_WERROR` : `false`
>
> They can be overridden on the command line.
>
> I had to do the following two things for the build to pass:
>
> 1. Disable `-Werror` for the `javafx.graphics` module until [JDK-8334137](https://bugs.openjdk.org/browse/JDK-8334137) is fixed. The warning generated when using `sun.misc.Unsafe` in JDK 22 or later cannot be suppressed, so we must not use `-Werror` when compiling the graphics module.
> 2. Define module-specific `extraLintOptions` in the swing module to disable the "options" lint warning, which is enabled by default. That warning is generated because we (necessarily) use `--source 21` instead of `--release 21` for the Swing module, and don't set the location of the system modules.
>
> I tested this, both locally and via GHA, in the following two branches, each of which introduces an error, the first tests that a removal warning will fail the build and the second tests that a missing explicit constructor will fail the build:
>
> * [test-Werror-removal](https://github.com/kevinrushforth/jfx/tree/test-Werror-removal) : [GHA workflow](https://github.com/kevinrushforth/jfx/actions/runs/9664971290)
> * [test-Werror-implicit-ctor](https://github.com/kevinrushforth/jfx/tree/test-Werror-implicit-ctor) : [GHA workflow](https://github.com/kevinrushforth/jfx/actions/runs/9664924813)
Marked as reviewed by arapte (Reviewer).
A few observations on usage:
1. `gradle -PLINT=all` command would fail, or if we enable any other lint warning which if occurs would fail the build.
2. `gradle -PTEST_JAVAC_WERROR=true :controls:test` does not fail even if a warning is present, as by default lint warnings are disabled for test. We need to enable any specific warning that we are looking for; an example as
`gradle -PTEST_LINT=options,unchecked -PTEST_JAVAC_WERROR=true :controls:test`
3. Currently, `gradle -PTEST_LINT=all,-options -PTEST_JAVAC_WERROR=true :controls:test` fails. (with any test task)
-------------
PR Review: https://git.openjdk.org/jfx/pull/1475#pullrequestreview-2142646395
PR Comment: https://git.openjdk.org/jfx/pull/1475#issuecomment-2192362979
More information about the openjfx-dev
mailing list