[Misc] Use instanceof pattern matching instead of explicit casts (SonarQube java:S6201) - #391
Merged
Merged
Conversation
…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>
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'" — across:xwiki-rendering-api(24, mostly theequals()implementations of theBlockhierarchy)xwiki-rendering-transformation-macro(10) andxwiki-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)instanceofcheck; where an explicit local was declared just to hold the cast, that declaration is removed and the pattern variable takes its name.Clarifications
XDOMXMLChainingStreamRenderer.serializeParameter) is unchanged.XHTMLXWikiGeneratorListener.onImage—if (!(reference instanceof XWikiWikiReference xwikiReference)), the variable being used in theelsebranch.AbstractX509FileSystemStore.isMulti—!(store instanceof FileStoreReference fileStore) || fileStore.isMulti(), where the||right-hand side only runs when the check succeeded.PutFootnotesMacrotwo 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
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