[Misc] Use instanceof pattern matching instead of explicit casts (SonarQube java:S6201) - #1854
Merged
Conversation
…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>
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.
Jira URL
N/A —
[Misc]commit, no JIRA issue (SonarQube cleanup).Changes
Description
java:S6201issues — "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)instanceofcheck; where an explicit local was declared just to hold the cast, that declaration is removed and the pattern variable takes its name.Clarifications
serializeParameter/getInstanceoverload sets) is unchanged.xwiki-commons-crypto-cipher(4 more sites) was deliberately left out: removing the coveredCHECKCASTinstructions there takes the module's JaCoCo instruction ratio from 0.70 to 0.69 and failsjacoco: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
BUILD SUCCESS— full unit-test suites, Checkstyle, Revapi and the JaCoCo coverage gate all pass.Expected merging strategy
Related
Part of the same SonarQube sweep (one PR per repo, mergeable independently):
java:S6201fixes in the crypto modulesjava:S6201fixes across the rendering modulesjava:S8924fixes in unit testsGenerated by Claude Code