Add FindThreadGroupUsages recipe (RSPEC-S3014) - #1063
Merged
Merged
Conversation
Marks uses of `java.lang.ThreadGroup`, which was originally intended to help with thread management but has serious design flaws: most methods are deprecated or unsafe, and modern code should use `java.util.concurrent.ExecutorService` instead. Sites flagged: - `new ThreadGroup(...)` constructor calls - `Thread.getThreadGroup()` method calls - Method invocations on `ThreadGroup` receivers Search-only. Migrating off `ThreadGroup` typically requires introducing an executor and restructuring how threads are grouped, which is not automatable. Tags the recipe with RSPEC-S3014.
Jammy-Louie
approved these changes
Sep 16, 2026
bblincoe
self-requested a review
September 16, 2026 19:50
bblincoe
approved these changes
Sep 16, 2026
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
Adds a search-only recipe that flags uses of
java.lang.ThreadGroup.ThreadGroupwas originally intended to help with thread management, but its API has serious design flaws — most methods are deprecated or unsafe, and modern code should usejava.util.concurrent.ExecutorServiceinstead.Implements SonarQube RSPEC-S3014.
Design notes
UsesType<>("java.lang.ThreadGroup")ORUsesMethod<>("java.lang.Thread getThreadGroup()")— the visitor only walks CUs that could match.new ThreadGroup(...)—visitNewClass+TypeUtils.isOfClassType.Thread.getThreadGroup()— dedicatedMethodMatcher.ThreadGroupreceiver (e.g.group.activeCount()) — checksm.getSelect().getType().ThreadGrouptypically requires introducing an executor and restructuring how threads are grouped; not automatable.estimatedEffortPerOccurrence = 30 minutes— realistic manual fix cost, higher than a call-removal recipe.Files
src/main/java/org/openrewrite/staticanalysis/FindThreadGroupUsages.javasrc/test/java/org/openrewrite/staticanalysis/FindThreadGroupUsagesTest.java— 5 testssrc/main/resources/META-INF/rewrite/recipes.csv— regenerated (single-row addition, no drift)Test plan
./gradlew compileJava— passes./gradlew test --tests FindThreadGroupUsagesTest— 5/5 green./gradlew recipeCsvGenerate recipeCsvValidateContent— cleanTest coverage
new ThreadGroup("workers")→ flagged (also verifies surroundingnew Thread(group, ...)andt.start()are not flagged) —@DocumentExampleThread.currentThread().getThreadGroup()→ flaggedgroup.activeCount()wheregroupis aThreadGroupparameter → flaggednew Thread(...)/setName/start/interrupt→ not flagged (negative)com.example.ThreadGroupclass → not flagged (confirms FQN matching, not simple-name matching)