[Misc] Use instanceof pattern matching instead of explicit casts (SonarQube java:S6201) - #1858
Merged
Conversation
…arQube java:S6201) * Convert 53 instanceof-and-cast sites in xwiki-commons-component-default, xwiki-commons-filter-api, xwiki-commons-job-api, xwiki-commons-logging-api and xwiki-commons-properties to Java 16+ instanceof pattern matching. 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.
Mechanical SonarCloud cleanup: converts every
java:S6201("Replace this instanceof check and castwith 'instanceof Foo foo'") issue open in five commons modules to Java 16+ instanceof pattern
matching — 53 issues, no behaviour change.
Modules:
xwiki-commons-component-default,xwiki-commons-filter-api,xwiki-commons-job-api,xwiki-commons-logging-api,xwiki-commons-properties.The transform is either "bind the existing explicit local into the pattern and delete its
declaration" or "bind a new pattern variable and drop the inline casts inside its flow scope". Casts
to a different type, or outside the pattern variable's scope, were left untouched.
SonarCloud: https://sonarcloud.io/project/issues?id=org.xwiki.commons%3Axwiki-commons&rules=java%3AS6201
Verified with
mvn install -Plegacy,qualityon the five modules (tests, Checkstyle, Revapi andJaCoCo all green).
Related (same sweep, one PR per repo):
Generated by Claude Code