chore(QTDI-2893): use pattern matching for instanceof (S6201)#1227
Open
undx wants to merge 2 commits into
Open
chore(QTDI-2893): use pattern matching for instanceof (S6201)#1227undx wants to merge 2 commits into
undx wants to merge 2 commits into
Conversation
Replace `instanceof` + manual cast patterns with Java 17 pattern matching for instanceof to reduce Sonar warnings (java:S6201). Both `(X) value` and `X.class.cast(value)` cast forms are handled. Excluded cases: - Conditions combined with `||` (pattern matching incompatible with alternation): AvroSchemaCache, SchemaConverter (Double||Float). - ParameterSetter#set: target variable declared outside the `if` block (would require restructuring). - Casts to a type different from the `instanceof` check (not S6201).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes several Java 17 code paths by replacing instanceof + explicit cast patterns with pattern matching for instanceof, primarily to address Sonar warning java:S6201 across the component runtime and related modules.
Changes:
- Refactors multiple
instanceofblocks to use Java 17 pattern variables (e.g.,if (x instanceof Foo foo)). - Simplifies downstream usage by removing redundant
Class#cast()and explicit casts once a pattern variable is available. - Applies the refactor consistently across runtime, DI studio, Beam integration, tools, and tests.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| component-tools/src/main/java/org/talend/sdk/component/tools/validator/ActionValidator.java | Uses pattern matching for ParameterizedType handling in return-type validation. |
| component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/RuntimeContextInjector.java | Refactors Delegated handling to use a pattern variable. |
| component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/ParameterSetter.java | Refactors list access guarded by instanceof List to use a pattern variable. |
| component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/AfterVariableExtracter.java | Refactors Delegated handling to use a pattern variable. |
| component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java | Refactors several instanceof/cast sites in schema discovery and result interpretation. |
| component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/OutputsHandler.java | Refactors Record handling to use a pattern variable. |
| component-runtime-testing/component-runtime-http-junit/src/main/java/org/talend/sdk/component/junit/http/internal/impl/DefaultResponseLocator.java | Refactors ParameterizedType equality path to use a pattern variable. |
| component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/ProducerFinderImplTest.java | Refactors a test helper Record cast to pattern matching. |
| component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/xbean/converter/SchemaConverter.java | Refactors primitive-wrapper handling in JSON conversion (and exposes a Float-cast bug in the touched hunk). |
| component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/ServiceHelper.java | Refactors BaseService cast to pattern matching. |
| component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java | Refactors JsonObject / JsonArray casts in jsonToMap to pattern matching. |
| component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java | Refactors datetime-related instanceof casts to pattern matching. |
| component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroSchemaCache.java | Refactors SchemaImpl cast to pattern matching. |
| component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java | Refactors multiple mapping/casting branches to pattern matching. |
| component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroEntryBuilder.java | Refactors AvroSchema cast to pattern matching. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ozhelezniak-talend
approved these changes
May 22, 2026
Contributor
ozhelezniak-talend
left a comment
There was a problem hiding this comment.
LGTM
potentially might have a merge conflict with my pr...
Member
Author
Sure, you'll merge first, will rebase then. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

https://qlik-dev.atlassian.net/browse/QTDI-2893
Replace
instanceof+ manual cast patterns with Java 17 pattern matching for instanceof to reduce Sonar warnings (java:S6201).Both
(X) valueandX.class.cast(value)cast forms are handled.Excluded cases:
||(pattern matching incompatible with alternation): AvroSchemaCache, SchemaConverter (Double||Float).ifblock (would require restructuring).instanceofcheck (not S6201).Requirements
Why this PR is needed?
What does this PR adds (design/code thoughts)?
AI generated code
https://internal.qlik.dev/general/ways-of-working/code-reviews/#guidelines-for-ai-generated-code