Skip to content

(chores): fix SonarCloud S1871 duplicate branch violations#22551

Open
orpiske wants to merge 1 commit intoapache:mainfrom
orpiske:ci-camel-4-sonarcloud-S1871
Open

(chores): fix SonarCloud S1871 duplicate branch violations#22551
orpiske wants to merge 1 commit intoapache:mainfrom
orpiske:ci-camel-4-sonarcloud-S1871

Conversation

@orpiske
Copy link
Copy Markdown
Contributor

@orpiske orpiske commented Apr 11, 2026

Summary

  • Merge duplicate conditional branches (S1871) across 45 files in core, components, tooling, and DSL modules
  • Combine if-else branches returning identical results using || operators
  • Extract helper methods where combining conditions would be too complex (e.g., matchesTemplateKey(), isConsoleLogDependency(), isSimpleExpression())
  • Use Set-based lookup for HealthCheckHelper.isReservedKey() replacing 13 duplicate branches
  • Consolidate switch case fall-throughs in MethodBodySourceCodeEmitter

Test plan

  • Core modules compile successfully (mvn -DskipTests install)
  • All modules formatted with mvn formatter:format impsort:sort
  • CI build validates all changes compile and tests pass

Claude Code on behalf of Otavio R. Piske

…DSL modules

Merge duplicate conditional branches that have identical implementations,
addressing 79 SonarCloud S1871 violations. Changes include combining
if-else branches with || operators, extracting helper methods for complex
conditions, using Set-based lookups for repeated equality checks, and
consolidating switch case fall-throughs.

Claude Code on behalf of Otavio R. Piske

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@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 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 Author

@orpiske orpiske left a comment

Choose a reason for hiding this comment

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

I'm not very satisfied w/ the results on this one. I'm likely going to close it without merge on Monday.

} else if (MACHINE_TRANSLATION.getPath().equals(applicationPath)) {
return new CustomNlpPredictor<String>(endpoint);
} else if (MULTIPLE_CHOICE.getPath().equals(applicationPath)) {
} else if (TEXT_GENERATION.getPath().equals(applicationPath)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if this is better.

if (!inWord && !doNotIncludeSymbols.contains(String.valueOf(c))) {
curToken.append(c);
} else if ('"' != c || (!curToken.isEmpty() && curToken.charAt(curToken.length() - 1) == '\\')) {
if ((!inWord && !doNotIncludeSymbols.contains(String.valueOf(c)))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does it look better? I'm not convinced on this one ..

@github-actions
Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-ai/camel-djl
  • components/camel-aws/camel-aws-xray
  • components/camel-bean
  • components/camel-bindy
  • components/camel-cxf/camel-cxf-soap
  • components/camel-cxf/camel-cxf-spring-soap
  • components/camel-http
  • components/camel-jt400
  • components/camel-mail
  • components/camel-milo
  • components/camel-mllp
  • components/camel-netty-http
  • components/camel-resilience4j
  • components/camel-saxon
  • components/camel-spring-parent/camel-spring-xml
  • components/camel-sql
  • components/camel-undertow
  • core/camel-api
  • core/camel-base-engine
  • core/camel-core-catalog
  • core/camel-core-engine
  • core/camel-core-model
  • core/camel-core-processor
  • core/camel-health
  • core/camel-management
  • core/camel-support
  • core/camel-util
  • core/camel-xml-io
  • dsl/camel-jbang/camel-jbang-core
  • dsl/camel-jbang/camel-jbang-mcp
  • dsl/camel-kamelet-main
  • tooling/camel-util-json
  • tooling/maven/camel-maven-plugin
  • tooling/maven/camel-package-maven-plugin
  • tooling/openapi-rest-dsl-generator

ℹ️ Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the test-dependents label to force testing all dependents.

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • components/camel-ai/camel-djl: 1 test(s) disabled on GitHub Actions
  • components/camel-http: 1 test(s) disabled on GitHub Actions
  • components/camel-mllp: 2 test(s) disabled on GitHub Actions
  • components/camel-undertow: 1 test(s) disabled on GitHub Actions
  • core/camel-management: 4 test(s) disabled on GitHub Actions
  • dsl/camel-jbang/camel-jbang-core: 1 test(s) disabled on GitHub Actions
  • dsl/camel-jbang/camel-jbang-mcp: 1 test(s) disabled on GitHub Actions

💡 Manual integration tests recommended:

You modified dsl/camel-jbang/camel-jbang-core. The related integration tests in dsl/camel-jbang/camel-jbang-it are excluded from CI. Consider running them manually:

mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
Build reactor — dependencies compiled but only changed modules were tested (35 modules)
  • Camel :: AI :: Deep Java Library
  • Camel :: API
  • Camel :: AWS :: XRay (deprecated)
  • Camel :: Base Engine
  • Camel :: Bean
  • Camel :: Bindy
  • Camel :: CXF :: SOAP
  • Camel :: CXF :: SOAP :: Spring
  • Camel :: Core Catalog
  • Camel :: Core Engine
  • Camel :: Core Model
  • Camel :: Core Processor
  • Camel :: HTTP
  • Camel :: Health
  • Camel :: JBang :: Core
  • Camel :: JBang :: MCP
  • Camel :: Java Toolbox for IBM i
  • Camel :: Kamelet Main
  • Camel :: MLLP
  • Camel :: Mail
  • Camel :: Management
  • Camel :: Maven Plugins :: Camel Maven Package
  • Camel :: Maven Plugins :: Camel Maven Plugin
  • Camel :: Milo
  • Camel :: Netty HTTP
  • Camel :: Resilience4j
  • Camel :: SQL
  • Camel :: Saxon
  • Camel :: Spring XML
  • Camel :: Support
  • Camel :: Tooling :: OpenApi REST DSL Generator
  • Camel :: Undertow
  • Camel :: Util
  • Camel :: Util :: JSon
  • Camel :: XML IO

⚙️ View full build and test results

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.

1 participant