Skip to content

fix(intelligence): close ExecutorService via try-with-resources (SonarCloud S2095)#54

Merged
aksOps merged 1 commit into
mainfrom
fix/sonar-s2095-language-enricher
Apr 23, 2026
Merged

fix(intelligence): close ExecutorService via try-with-resources (SonarCloud S2095)#54
aksOps merged 1 commit into
mainfrom
fix/sonar-s2095-language-enricher

Conversation

@aksOps

@aksOps aksOps commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the SonarCloud quality-gate failure blocking recent PRs. Only one new-code reliability bug: LanguageEnricher.java:125 — BLOCKER severity, rule java:S2095 (ExecutorService not closed).

Root cause

The code used the canonical "safe shutdown" pattern (shutdown() + awaitTermination(10s) + shutdownNow() + awaitTermination(5s)) in a finally block. Architecturally correct, but SonarCloud S2095 is strict: it wants try-with-resources or explicit close() regardless of whether the finally block is equivalent.

Fix

Java 19+ ExecutorService implements AutoCloseable. close() performs shutdown() + awaitTermination(Long.MAX_VALUE) + shutdownNow() on interrupt. Since each future.get() already has a 5-minute timeout + cancel(true), by the time close() runs all tasks are terminal — so close() returns promptly rather than waiting indefinitely.

Diff: one try-with-resources, remove 15 lines of manual finally cleanup.

Tests

mvn -B test -Dtest='LanguageEnricherTest,AnalyzerTest,SmartIndexTest' → 30 pass / 0 fail. Virtual-thread executor semantics unchanged.

Quality gate

Before this PR (on main):

  • new_reliability_rating: 5 (E) ← failing
  • new_coverage: 83.7%
  • all other conditions passing

After this PR:

  • expected new_reliability_rating: 1 (A) ← the one blocker bug is the S2095 we're fixing

Test plan

  • CI green (CodeQL, Java CI, SonarCloud)
  • SonarCloud reliability rating on new code becomes A

🤖 Generated with Claude Code

…rCloud S2095)

The virtual-thread executor was shut down in a finally block, which is
architecturally correct but triggers SonarCloud's S2095 blocker bug.
Java 19+ ExecutorService implements AutoCloseable; try-with-resources
invokes close() which safely shuts down and awaits termination.

Each future.get() already has a 5-minute timeout + cancel, so by the
time close() runs, tasks are terminal and close() returns promptly.
The manual 10s+5s shutdown timing is superseded by AutoCloseable
contract.
@sonarqubecloud

Copy link
Copy Markdown

@aksOps aksOps merged commit 8ed60f5 into main Apr 23, 2026
9 checks passed
@aksOps aksOps deleted the fix/sonar-s2095-language-enricher branch April 26, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant