Skip to content

CAMEL-23271: Fix SonarCloud blocker reliability issues (resource leaks)#22343

Open
gnodet wants to merge 5 commits intoapache:mainfrom
gnodet:CAMEL-23271-fix-sonarcloud-blocker-resource-leaks
Open

CAMEL-23271: Fix SonarCloud blocker reliability issues (resource leaks)#22343
gnodet wants to merge 5 commits intoapache:mainfrom
gnodet:CAMEL-23271-fix-sonarcloud-blocker-resource-leaks

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented Mar 30, 2026

Summary

Fix all 31 SonarCloud blocker reliability issues (java:S2095 — resource leaks):

  • JcrConsumer: ScheduledExecutorService created as local variable but never stored or shut down. Fixed by storing in a field and shutting down via ExecutorServiceManager.shutdownNow() in cancelSessionListenerChecker()
  • ModelWriterGeneratorMojo: DynamicClassLoader (extends URLClassLoader) never closed. Fixed with try-with-resources
  • 23 HttpClient false positives: Set sonar.java.source=${jdk.version} so SonarCloud analyzes against the correct API surface (HttpClient only implements AutoCloseable since Java 21, but project compiles with --release 17)
  • 6 ExecutorService/CamelContext false positives: Suppressed with // NOSONAR or @SuppressWarnings("java:S2095") at statement level (not method level) with explanatory comments on AggregateReifier, ThreadsReifier, SalesforceComponent, and CamelYamlParser

Test plan

  • CI passes — changes are minimal (1 real bug fix, 1 resource cleanup, rest are annotations/config)
  • Verify SonarCloud blocker count drops to 0 after merge

@gnodet gnodet requested review from apupier and oscerd March 30, 2026 15:03
@gnodet gnodet marked this pull request as draft March 30, 2026 15:07
- JcrConsumer: store ScheduledExecutorService in a field and shut it down in doStop()
- ModelWriterGeneratorMojo: wrap DynamicClassLoader in try-with-resources
- Set sonar.java.source=17 to eliminate 23 HttpClient false positives
- Add @SuppressWarnings for ExecutorService/CamelContext lifecycle false positives

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet force-pushed the CAMEL-23271-fix-sonarcloud-blocker-resource-leaks branch from 8aae561 to 749676c Compare March 30, 2026 15:09
@gnodet gnodet marked this pull request as ready for review March 30, 2026 15:18
Address review feedback: use the existing jdk.version property
instead of hardcoding '17', consistent with other compiler settings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet
Copy link
Copy Markdown
Contributor Author

gnodet commented Mar 30, 2026

Would it make sense to use ${jdk.version} here?

Good catch @Croway — changed to ${jdk.version} for consistency with the other compiler settings. Fixed in 769137a.

Claude Code on behalf of Guillaume Nodet

@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.

gnodet and others added 3 commits March 30, 2026 18:00
- Move sonar.java.source above the NOTE comment so it stays with
  sonar.coverage.jacoco.xmlReportPaths (apupier)
- Replace method-level @SuppressWarnings with line-level // NOSONAR
  to avoid masking future real leaks (squakez)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Narrow suppression scope: move @SuppressWarnings("java:S2095") from
method level to the local variable declarations where the resources
are created, so it won't mask future issues in the same methods.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CamelContext implements AutoCloseable, so use try-with-resources
instead of manual stop in finally block. Removes the need for
@SuppressWarnings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet requested review from Croway, apupier and squakez March 30, 2026 17:40
@apupier
Copy link
Copy Markdown
Contributor

apupier commented Mar 31, 2026

/component-test jcr salesforce

<!-- reproducible builds: https://maven.apache.org/guides/mini/guide-reproducible-builds.html -->
<project.build.outputTimestamp>2026-02-17T16:11:10Z</project.build.outputTimestamp>

<!-- Tell SonarCloud which Java source level to use for analysis -->
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.

i think this comment is very redundant and does not add value (not a blocker)

@github-actions
Copy link
Copy Markdown
Contributor

/component-test jcr salesforce tests passed successfully.

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.

4 participants