fix(sonar): use dedicated File assertions (S5838) - #376
Merged
Conversation
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KW6yskY3pE759XUg2UUtf8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 2 of the 13 open
java:S5838findings:assertThat(file.canRead()).isTrue()→assertThat(file).canRead()(same forcanWrite()), using AssertJ's dedicatedFileAssert.Triage note on the other 11 S5838 findings + all 10 S3415 findings
I checked every remaining
S5838/S3415finding before touching anything, since the last PR (#368) taught me not to trust Sonar's suggested rewrite blindly. Result: all of them are false positives, and I've left them untouched:S5838findings ("Use isZero() instead") are all on values statically typedNumber(FilteredAggregate.sum(),Compute.filteredSum(...)) — AssertJ has noassertThat(Number)overload andObjectAssert/AbstractObjectAsserthave noisZero()method (verified viajavapagainstassertj-core-3.27.3.jar). Applying the suggested fix does not compile..isEqualTo(0L)is the correct form for aNumber-typed value.S3415findings ("swap actual/expected") are all on AssertJ's fluentassertThat(actual).isEqualTo(expected)/.isInstanceOf(...)chains, already in the correct, idiomatic order. The rule (taggedjunitupstream, designed for two-argassertEquals(expected, actual)) doesn't understand AssertJ's fluent single-argument form — one flagged line is evenassertThat(x).isInstanceOf(Key.class), which has no "expected/actual" concept for the rule to check.Both categories are unfixable-as-suggested without breaking the build (S5838) or actively making the code worse (S3415), so this PR only contains the 2 genuine fixes.
Test plan
Assertions.assertThat(File)/AbstractFileAssert#canRead()/canWrite()are valid).