Skip to content

Fail the build on four Error Prone checks - #201

Open
abashev wants to merge 10 commits into
21.X.Xfrom
abashev/Fix-error-prone-issues
Open

abashev wants to merge 10 commits into
21.X.Xfrom
abashev/Fix-error-prone-issues

Conversation

@abashev

@abashev abashev commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Error Prone has run on every compile, but nothing it reported failed the build except two JUnit checks, and the warnings scrolled past. This is the first step towards making it fail the build: the suppressions go, and four checks become errors once their findings are fixed.

  • @SuppressWarnings. 105 of the 110 are gone. They hid almost nothing. 94 named their checks with palantir-baseline's for-rollout: prefix, which plain Error Prone does not take for a check's name, so NullAway and the rest reported those lines all along. Others named checks this build does not run (TooManyArguments, ImmutablesStyle), IntelliJ inspections, or javac's unchecked lint, which is off. Removing UnicodeEscape's brings back its one finding.
  • Immutable stays suppressed. The five suppressions on Doc's and Level's memoized suppliers remain. Immutable is an error by default, and the check is right: Suppliers.memoize caches its value, so Break, Token and NonBreakingSpace, which are @Immutable and extend Doc, are not immutable. Fixing that is a change of its own.
  • Four checks are errors, after their findings are fixed. Each one has its own commit, and every commit builds. All the checks that fail the build are now set in one block; the ones that were only listed as comments for later are gone.
    • UnusedVariable: ExecutableTransform's logger, StringWrapper's endLine, and the stderr that two MainTest tests read after the process had exited.
    • SameNameButDifferent: in PalantirJavaFormatSettings, State named both IntelliJ's @State and the settings bean. The bean is now StoredSettings. Its class name is not stored in .idea/open-java-format.xml, and PalantirJavaFormatSettingsTest loads files written before.
    • RefactorSwitch: four switch statements that returned from every case are now the switch expressions they return.
    • FormatStringConcatenation: seven calls in the tests pass a format string and its arguments to AssertJ's describedAs, hasMessage and isEqualTo and to Guava's checkState, instead of a concatenated string. In JavaCommentsHelperTest the expected comment stays written out like its input, and the check is suppressed on that test.

Tests

./gradlew test passes on JDK 21: 1557 tests, 14 skipped. With an unused local added to CommandLineOptionsParser, :open-java-format:compileJava fails with error: [UnusedVariable].

Not here

166 warnings remain: NullAway 102, CollectorMutability 12, EffectivelyPrivate 12, StringConcatToTextBlock 9, ConstantNaming 5, and 1 to 3 each for 17 more checks. There are also 133 suggestions (StaticImport 86, LexicographicalAnnotationListing 23, and others). Those checks, Immutable included, follow one at a time.

Of the 110 annotations 105 hid nothing. 94 named their checks with
palantir-baseline's for-rollout: prefix, which plain Error Prone does
not take for the check's name: NullAway and the rest reported those
lines all along. Others named checks this build does not run
(TooManyArguments, ImmutablesStyle), IntelliJ inspections, or javac's
unchecked lint, which is off. Without UnicodeEscape's, its one finding
shows.

The five on Doc's and Level's memoized suppliers stay: Immutable is an
error, and the suppliers are mutable caches that the check rightly
rejects. They need their own change.
ExecutableTransform's logger, StringWrapper's endLine and the stderr
two MainTest tests read after the process had exited were never read.
They are gone, and Error Prone now fails the build on the next one.
In PalantirJavaFormatSettings `State` named both IntelliJ's @State
annotation and the settings' own State class. The annotation is now
written out in full, which leaves the name to the class.
The switch statements in DimensionHelpers.extractDims,
CommandLineOptionsParser's two range parsers and SnippetFormatter's
snippetWrapper returned from every case. Each is now the switch
expression it returns, with yield where a case has statements before
its value.
Eight calls in the tests built a message or an expected string by
concatenation and handed it to a method that formats one itself:
AssertJ's describedAs, hasMessage and isEqualTo(String, Object...) and
Guava's checkState. They now pass a format string and its arguments.
The checks that fail the build join excludedPaths in a single block,
in alphabetical order. The checks that were only listed as comments
for later are gone; the findings still to fix are in the build output.
State also named IntelliJ's @State annotation on the same class, which
the previous commit wrote out in full to tell the two apart. The class
gets a name of its own and the annotation its import back.

The class name is not in .idea/open-java-format.xml: IntelliJ writes
the bean's fields into the component element, and
PalantirJavaFormatSettingsTest loads files written before.
…fTheRun

As a format string the expected comment no longer read like the input
it is rewritten from. The concatenation is back, with
FormatStringConcatenation suppressed on the test.
The 21.X.X merge brought in Signature, whose bundled field only went
into the serialized signature and carried a suppression. jars() now
picks the jars by it: the hash is there exactly when the build declared
none of its own, so the step formats with the same jars as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant