Skip to content

[Misc] Use isEmpty() instead of comparing length() to zero - #387

Merged
vmassol merged 1 commit into
masterfrom
claude/peaceful-archimedes-vwbl7e
Jul 26, 2026
Merged

[Misc] Use isEmpty() instead of comparing length() to zero#387
vmassol merged 1 commit into
masterfrom
claude/peaceful-archimedes-vwbl7e

Conversation

@vmassol

@vmassol vmassol commented Jul 26, 2026

Copy link
Copy Markdown
Member

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() == 0X.isEmpty()
  • X.length() > 0 / X.length() != 0!X.isEmpty()

isEmpty() is available on every receiver involved here (String since Java 6, CharSequence since Java 15, StringBuilder/StringBuffer), and XWiki targets Java 17. Only the flagged comparison is rewritten — surrounding clauses such as buffer.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 the event / xdomxml10 / xhtml / xwiki20 syntax modules. The bulk sits in the whitespace filters (XHTMLWhitespaceXMLFilter, XWikiXHTMLWhitespaceXMLFilter) and in XWikiSyntaxEscapeWikiPrinter.

Test plan

  • mvn clean install -Plegacy,quality over 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

* 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>
@vmassol vmassol added the llm-agent label Jul 26, 2026 — with Claude
@vmassol vmassol self-assigned this Jul 26, 2026
@claude claude Bot locked as resolved and limited conversation to collaborators Jul 26, 2026
@vmassol
vmassol merged commit c8f4890 into master Jul 26, 2026
3 checks passed
@vmassol
vmassol deleted the claude/peaceful-archimedes-vwbl7e branch July 26, 2026 08:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant