Repository navigation
SONARJAVA-7188 SONARJAVA-4606 Improvements for the rule S7158 - #6359
Conversation
LiteralUtils.isZero compared the literal's decimal token text, so length() == 0 was flagged but the equivalent length() == 0x0, 00 or 0b0 was not. Compare the parsed literal value instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…risons Comparing "s.trim().length()" to zero is a blankness check, so report it with an "isBlank()" message and quick fix instead of "isEmpty()". Gated on Java 11, where "String.isBlank()" was introduced. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… comparisons "strip()" removes exactly the characters "isBlank()" treats as white space, so the rewrite is equivalent. "trim()" removes every character up to U+0020 instead, so it disagrees on control characters below U+0020 and on Unicode white space above it; those cases keep the suggestion but the issue message and the quick-fix label state what the replacement changes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lijun-chen-sonarsource
left a comment
There was a problem hiding this comment.
LGTM!
Left one test suggestion, if that makes sense.
Below Java 11 neither "strip()" nor "trim()" may be rewritten to "isBlank()", since that method does not exist yet. Pin that the comparison is still reported as an emptiness check on the trimmed string, with an "isEmpty()" quick fix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Code Review ✅ Approved 1 closed / 1 findings🟡 Medium risk · The new isBlank() quick fixes for trim/strip checks may change whitespace semantics, while expanded zero-literal parsing also affects analyzer findings. Improves rule S7158 to detect zero literals written in any base and to suggest ✅ 1 closedClosed: Cross-PR: S7158 and S9432 both flag trim().length() with conflicting advice
Verification Rules 1/1 met Repos 3 inspected · PRs 1 inspectedFunctional validation No results Rules 1 passed 2 not applicable
Broader impact Repos 3 inspected PRs 1 inspectedCross-repo 3 repositories inspected 0 open impacts
Cross-PR 1 PR inspected 0 open impactsAuto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |




Uh oh!
There was an error while loading. Please reload this page.