fix(intelligence): close ExecutorService via try-with-resources (SonarCloud S2095)#54
Merged
Merged
Conversation
…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.
|
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.



Summary
Closes the SonarCloud quality-gate failure blocking recent PRs. Only one new-code reliability bug:
LanguageEnricher.java:125— BLOCKER severity, rulejava:S2095(ExecutorService not closed).Root cause
The code used the canonical "safe shutdown" pattern (
shutdown() + awaitTermination(10s) + shutdownNow() + awaitTermination(5s)) in afinallyblock. Architecturally correct, but SonarCloud S2095 is strict: it wantstry-with-resourcesor explicitclose()regardless of whether the finally block is equivalent.Fix
Java 19+
ExecutorServiceimplementsAutoCloseable.close()performsshutdown()+awaitTermination(Long.MAX_VALUE)+shutdownNow()on interrupt. Since eachfuture.get()already has a 5-minute timeout +cancel(true), by the timeclose()runs all tasks are terminal — soclose()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)← failingnew_coverage: 83.7%✅After this PR:
new_reliability_rating: 1 (A)← the one blocker bug is the S2095 we're fixingTest plan
🤖 Generated with Claude Code