Skip to content

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

Merged
vmassol merged 1 commit into
masterfrom
claude/nifty-bell-jd68vp
Jul 29, 2026
Merged

[Misc] Use instanceof pattern matching instead of explicit casts (SonarQube java:S6201)#1854
vmassol merged 1 commit into
masterfrom
claude/nifty-bell-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 73 open SonarCloud java:S6201 issues — "Replace this instanceof check and cast with 'instanceof Foo foo'" — in the crypto modules:
    • xwiki-commons-crypto-common (14)
    • xwiki-commons-crypto-password (31)
    • xwiki-commons-crypto-pkix (14)
    • xwiki-commons-crypto-signer (8)
    • xwiki-commons-crypto-store-filesystem (6)
  • 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. the serializeParameter/getInstance overload sets) is unchanged.
  • xwiki-commons-crypto-cipher (4 more sites) was deliberately left out: removing the covered CHECKCAST instructions there takes the module's JaCoCo instruction ratio from 0.70 to 0.69 and fails jacoco:check. Lowering the pinned ratio to go green would be the wrong fix, so those 4 issues are left open for a change that also adds the missing tests.

Screenshots & Video

N/A — no UI change.

Executed Tests

mvn clean install -B -ntp -Plegacy,quality -pl \
  xwiki-commons-core/xwiki-commons-crypto/xwiki-commons-crypto-common,\
  xwiki-commons-core/xwiki-commons-crypto/xwiki-commons-crypto-password,\
  xwiki-commons-core/xwiki-commons-crypto/xwiki-commons-crypto-pkix,\
  xwiki-commons-core/xwiki-commons-crypto/xwiki-commons-crypto-signer,\
  xwiki-commons-core/xwiki-commons-crypto/xwiki-commons-crypto-store/xwiki-commons-crypto-store-filesystem

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 73 SonarCloud java:S6201 issues ("Replace this instanceof check and
  cast with 'instanceof Foo foo'") in the crypto modules (common, password,
  pkix, signer and store-filesystem).
* 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 PR created by an 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 04ca230 into master Jul 29, 2026
3 checks passed
@vmassol
vmassol deleted the claude/nifty-bell-jd68vp branch July 29, 2026 07:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

llm-agent PR created by an LLM agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant