Skip to content

[Misc] Use instanceof pattern matching instead of explicit casts (SonarQube java:S6201) - #391

Merged
vmassol merged 1 commit into
masterfrom
claude/peaceful-archimedes-jd68vp
Jul 29, 2026
Merged

[Misc] Use instanceof pattern matching instead of explicit casts (SonarQube java:S6201)#391
vmassol merged 1 commit into
masterfrom
claude/peaceful-archimedes-jd68vp

Conversation

@claude

@claude claude Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Jira URL

N/A — [Misc] commit, no JIRA issue (SonarQube cleanup).

Changes

Description

  • Fixes 52 open SonarCloud java:S6201 issues — "Replace this instanceof check and cast with 'instanceof Foo foo'" — across:
    • xwiki-rendering-api (24, mostly the equals() implementations of the Block hierarchy)
    • xwiki-rendering-transformation-macro (10) and xwiki-rendering-transformation-icon (2)
    • xwiki-rendering-syntax-xdomxml10 (7), -xhtml (2), -xwiki20 (1)
    • xwiki-rendering-macro-footnotes (3), xwiki-rendering-test (2), xwiki-rendering-wikimodel (1)
  • Each redundant cast is replaced by the pattern variable bound by the enclosing instanceof check; where an explicit local was declared just to hold the cast, that declaration is removed and the pattern variable takes its name.

Clarifications

  • The change is behaviour-neutral: the pattern variable has exactly the static type of the cast it replaces, so overload resolution (e.g. XDOMXMLChainingStreamRenderer.serializeParameter) is unchanged.
  • Two sites use flow scoping rather than a plain positive guard, which is why they read slightly differently:
    • XHTMLXWikiGeneratorListener.onImageif (!(reference instanceof XWikiWikiReference xwikiReference)), the variable being used in the else branch.
    • AbstractX509FileSystemStore.isMulti!(store instanceof FileStoreReference fileStore) || fileStore.isMulti(), where the || right-hand side only runs when the check succeeded.
  • In PutFootnotesMacro two conditions had to be re-wrapped to stay under the 120-character line limit once the pattern variable was added.

Screenshots & Video

N/A — no UI change.

Executed Tests

mvn clean install -B -ntp -Plegacy,quality -pl \
  xwiki-rendering-api,xwiki-rendering-wikimodel,xwiki-rendering-test,\
  xwiki-rendering-macros/xwiki-rendering-macro-footnotes,\
  xwiki-rendering-syntaxes/xwiki-rendering-syntax-xdomxml10,\
  xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml,\
  xwiki-rendering-syntaxes/xwiki-rendering-syntax-xwiki20,\
  xwiki-rendering-transformations/xwiki-rendering-transformation-icon,\
  xwiki-rendering-transformations/xwiki-rendering-transformation-macro

BUILD SUCCESS — full unit-test suites, Checkstyle, Revapi and the JaCoCo coverage gate all pass.

Expected merging strategy

  • Prefers squash: Yes
  • Backport on branches:
    • None — cleanup only, no need to backport.

Related

Part of the same SonarQube sweep (one PR per repo, mergeable independently):


Generated by Claude Code

…arQube java:S6201)

* Fixes 52 SonarCloud java:S6201 issues ("Replace this instanceof check and
  cast with 'instanceof Foo foo'") across the rendering API, the wikimodel,
  test, footnote-macro, xdomxml10/xhtml/xwiki20 syntax and the icon/macro
  transformation modules.
* Behaviour-neutral: each redundant cast is replaced by the pattern variable
  bound by the enclosing instanceof check.

Co-Authored-By: Vincent Massol <vincent@massol.net>
@claude claude Bot added the llm-agent label Jul 29, 2026
@claude claude Bot assigned vmassol Jul 29, 2026
@claude claude Bot locked as resolved and limited conversation to collaborators Jul 29, 2026
@vmassol
vmassol merged commit 0907f54 into master Jul 29, 2026
3 checks passed
@vmassol
vmassol deleted the claude/peaceful-archimedes-jd68vp branch July 29, 2026 07:57
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