RemoveUnusedImports removes imports when used in Generics only <!-- Thank you for…
- User
RemoveUnusedImports removes imports when used in Generics only
What version of OpenRewrite are you using?
I am using
- OpenRewrite v8.31.1
- Maven/Gradle plugin v6.40.0
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
<plugin> <groupId>org.openrewrite.maven</groupId> <artifactId>rewrite-maven-plugin</artifactId> <version>6.40.0</version> <executions> <execution> <phase>process-sources</phase> <goals> <goal>run</goal> </goals> <configuration> <activeRecipes combine.children="append"> <recipe>org.openrewrite.java.RemoveUnusedImports</recipe> <recipe>org.openrewrite.java.OrderImports</recipe> </activeRecipes> </configuration> </execution> </executions> </plugin>What is the smallest, simplest way to reproduce the problem?
import com.google.common.hash.BloomFilter; import java.util.concurrent.atomic.AtomicReference; @SuppressWarnings("UnstableApiUsage") public class BloomFilterRef<T> extends AtomicReference<BloomFilter<T>> { }What did you expect to see?
import com.google.common.hash.BloomFilter; import java.util.concurrent.atomic.AtomicReference; @SuppressWarnings("UnstableApiUsage") public class BloomFilterRef<T> extends AtomicReference<BloomFilter<T>> { }What did you see instead?
import java.util.concurrent.atomic.AtomicReference; @SuppressWarnings("UnstableApiUsage") public class BloomFilterRef<T> extends AtomicReference<BloomFilter<T>> { }What is the full stack trace of any errors you encountered?
stacktrace output hereAre you interested in contributing a fix to OpenRewrite?
Interface
No new interfaces are introduced.
- Assistant
Let me look at the existing tests for this recipe and reproduce the issue.
- Assistant
Let me write a reproduction test:
- Assistant
While that runs, let me examine how types are collected:
- Assistant
While waiting, let me check how
visitParameterizedTypevisits nested type parameters: - Assistant
Let me check existing tests around generics in the test file while waiting:
- Assistant
Waiting for the monitor event before proceeding.
- Assistant
The gradle output is buffered. I'll wait for the monitor events to fire.
- Assistant
While waiting, let me look at
NoMissingTypesto be sure it wouldn't block: - Assistant
The test is running. I'll wait for the monitor to fire.
- Assistant
I'm waiting on the Gradle test run (cold build, downloading dependencies and compiling
rewrite-core/rewrite-javafirst). The monitors will notify me when results appear. - Assistant
Dependencies are cached. The build should proceed. Waiting for the monitor events now.
- Assistant
Still compiling. Waiting for monitor notifications.
- Assistant
Monitors armed. I'll continue when the test results land.
- Assistant
Waiting on the build — I'll resume when the sleep timer or a monitor fires.
- Assistant
Compilation finished; tests should be running now. Waiting for the process-exit watcher.
- Assistant
While that runs, let me search the repository for tests that describe this exact scenario to understand expected semantics:
- Assistant
Waiting for the incremental test run to complete.
- Assistant
While the variants run, let me consider a scenario involving wildcard imports and generics:
- Assistant
Now let me apply the fix to
FindMissingTypes: - Assistant
Wait — I should confirm the reproduction before the fix is compiled, otherwise the pending test run can't distinguish "no repro" from "fixed". Reverting temporarily:
- Assistant
The repro test is now running against unfixed code. Waiting for the result.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.