Skip to content

(chores): fix SonarCloud S6201 in multiple modules#22303

Open
orpiske wants to merge 14 commits intoapache:mainfrom
orpiske:ci-camel-4-sonarcloud-S6201
Open

(chores): fix SonarCloud S6201 in multiple modules#22303
orpiske wants to merge 14 commits intoapache:mainfrom
orpiske:ci-camel-4-sonarcloud-S6201

Conversation

@orpiske
Copy link
Copy Markdown
Contributor

@orpiske orpiske commented Mar 28, 2026

Summary

  • Replace traditional instanceof check + explicit cast with Java 16+ pattern matching instanceof across 103 files in 14 module groups
  • Addresses ~250 SonarCloud S6201 violations (pattern matching for instanceof operator)
  • All changes are purely mechanical — semantically equivalent, no behavioral changes

Modules fixed:

  • Core: camel-support, camel-core-model, camel-core-languages, camel-base-engine, camel-yaml-io
  • AWS: camel-aws-bedrock, camel-aws-config, camel-aws2-ddb, camel-aws-secrets-manager, camel-aws-xray, camel-aws2-cw, camel-aws2-ec2, camel-aws2-eventbridge, camel-aws2-mq, camel-aws2-msk, camel-aws2-s3, camel-aws2-sns, camel-aws2-sqs, camel-aws2-sts, camel-aws2-translate
  • Azure: camel-azure-functions, camel-azure-servicebus
  • CXF: camel-cxf-common, camel-cxf-soap, camel-cxf-rest, camel-cxf-spring-soap, camel-cxf-spring-rest, camel-cxf-transport
  • Components: camel-elasticsearch, camel-jackson3 (+avro, +protobuf), camel-mail, camel-netty, camel-netty-http, camel-opensearch, camel-pqc, camel-sjms, camel-smpp, camel-spring-rabbitmq, camel-zeebe

Test plan

  • All affected modules compile with mvn -DskipTests install
  • Formatting verified with mvn formatter:format impsort:sort
  • CI passes on all affected modules

🤖 Generated with Claude Code on behalf of Otavio R. Piske

orpiske and others added 14 commits March 28, 2026 10:17
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@orpiske orpiske requested review from davsclaus and oscerd March 28, 2026 10:22
@github-actions
Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Copy link
Copy Markdown
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good mechanical refactoring overall. 103 files, all pattern matching transformations are semantically correct with proper variable scoping. CI is green.

One change in MailConverters.java is a semantic improvement (not purely mechanical) — see inline comment. One nit on variable naming in DefaultCxfBinding.java.

Claude Code on behalf of Guillaume Nodet

while (content instanceof MimeMultipart) {
if (multipart.getCount() < 1) {
while (content instanceof MimeMultipart mimeMultipart) {
if (mimeMultipart.getCount() < 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantic change — this is not a purely mechanical transformation.

The original code checked multipart.getCount() < 1, where multipart is the method parameter (the outer Multipart). That check was actually dead code: since we're inside for (int i = 0; i < size; i++) where size = multipart.getCount(), the outer count is always ≥ 1 when this line is reached.

The new code checks mimeMultipart.getCount() < 1, which is the inner MimeMultipart (the content variable). This is the correct thing to check — it guards against calling getBodyPart(0) on an empty multipart on the next line.

So this is actually a bug fix (replacing a dead guard with a meaningful one), not a mechanical refactoring. Worth noting since the PR claims "no behavioral changes". The fix itself is correct and an improvement.

} else if (part instanceof Element) {
addNamespace((Element) part, nsMap);
answer.add(new DOMSource((Element) part));
} else if (part instanceof Element element) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The pattern variable element here reuses the same name as the local variable Element element = null declared at line 1182 in the if branch above. They're in mutually exclusive scopes so this compiles and works correctly, but it's mildly confusing when reading the code. Consider using a different name like elem to make it visually distinct.

Not blocking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants