bazelbuild / bazelbuild/bazel

java_tools v13.5 changes -Werror:all to ignore ErrorProne warnings

Open
#26,370 2 comments 1 reaction 0 assignees View on GitHub
P2 team-Rules-Java type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

Prior to v13.5 of java_tools, ErrorProne warnings were reported as errors when using `-Werror`; after [this change](https://github.com/bazelbuild/bazel/commit/8aedcc4b36f3b5d534263d33e15de6a5cff076d3#diff-05b8235eacac75b4dffa5ea0ca1e50f206ed9650bf18e7f577d99472c229228bR163-R166), they are reported as warnings when using `-Werror`. Using `-Xep:diagnostic:severity` to manually change all the enabled-by-default warning-severity messages is nowhere near as straightforward as using `-Werror` to signal intent; besides, I think this may be unintentional, as the raw javac behaviour (at least in JDK 21) is for `-Werror` to make errorprone warnings into errors too.

The root cause is, I believe, the change in how a diagnostic is classed as being affected by `-Werror`; the new code rejects diagnostics without a lint category:

https://github.com/bazelbuild/bazel/blob/8aedcc4b36f3b5d534263d33e15de6a5cff076d3/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/FormattedDiagnostic.java#L159-L174

...whereas the previous code did not. Errorprone does not add a lint category to its diagnostics:

https://github.com/google/error-prone/blob/v2.32.0/check_api/src/main/java/com/google/errorprone/JavacErrorDescriptionListener.java#L131-L139

...so they are ignored, and are left as warnings.

### Which category does this issue belong to?

Java Rules

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

https://github.com/guyboltonking/bazel-java-tools-errorprone-ignores-werror

### Which operating system are you running Bazel on?

macOS, linux

### What is the output of `bazel info release`?

release 7.4.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

https://github.com/bazelbuild/bazel/commit/8aedcc4b36f3b5d534263d33e15de6a5cff076d3

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/FormattedDiagnostic.java at the linked lines, then reproduce the regression using the minimal example repository. Compare the v13.5 diagnostic classification with the preceding implementation and Error Prone's JavacErrorDescriptionListener; done means -Werror once again treats enabled Error Prone warnings as errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.