[Misc] Use isEmpty() instead of comparing length() to zero - #387
Merged
Conversation
* Fixes 40 SonarCloud java:S7158 issues ("Use isEmpty() to check whether a
StringBuilder is empty or not") across 15 files.
* Purely mechanical and behaviour-neutral: X.length() == 0 becomes
X.isEmpty() and X.length() > 0 / != 0 becomes !X.isEmpty().
Co-Authored-By: Vincent Massol <vincent@massol.net>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 40 SonarCloud issues for rule java:S7158 — "Use isEmpty() to check whether a StringBuilder is empty or not" — across 15 files.
The transformation is purely mechanical, single-line and behaviour-neutral:
X.length() == 0→X.isEmpty()X.length() > 0/X.length() != 0→!X.isEmpty()isEmpty()is available on every receiver involved here (Stringsince Java 6,CharSequencesince Java 15,StringBuilder/StringBuffer), and XWiki targets Java 17. Only the flagged comparison is rewritten — surrounding clauses such asbuffer.charAt(buffer.length() - 1)are left untouched. No signature, visibility or API change, so no backward-compatibility impact.Modules touched:
xwiki-rendering-api,xwiki-rendering-test,xwiki-rendering-wikimodel, and theevent/xdomxml10/xhtml/xwiki20syntax modules. The bulk sits in the whitespace filters (XHTMLWhitespaceXMLFilter,XWikiXHTMLWhitespaceXMLFilter) and inXWikiSyntaxEscapeWikiPrinter.Test plan
mvn clean install -Plegacy,qualityover all 7 modified modules — BUILD SUCCESS (Checkstyle, Spoon, Revapi, Enforcer and JaCoCo coverage gates included; full unit-test suites run, no failures).Generated by Claude Code