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 check
TypeUtils.asFullyQualifiedbehavior and write a reproduction test. - Assistant
Let me write a reproduction test first.
- Assistant
I'll add a reproduction test:
- Assistant
While the test runs, let me look at how
TypesInUsecollects types: - Assistant
Waiting for the test run to complete:
- Assistant
The first background task should finish shortly; the second was an accidental duplicate waiter. I'll wait for their notifications.
- Assistant
Let me wait for the test result before further tracing.
- Assistant
I'll wait for the monitor notification before proceeding.
- Assistant
Gradle is still compiling. I'll wait for the monitor event.
- Assistant
Waiting for the test run — no further action until the monitor fires.
- Assistant
Gradle is compiling the project (first build takes a while). Waiting for the monitor to fire.
- Assistant
While waiting, let me check the type mapping for identifiers within parameterized types in the Java parser:
- Assistant
Waiting for the build to finish.
- Assistant
The test run is still compiling. I'll pause until the background monitors notify me.
- Assistant
Waiting for background notifications.
- Assistant
Compilation is still ongoing (large multi-module build). Setting a longer waiter:
- Assistant
While waiting, let me verify how the extends clause is visited (cursor parentage matters for
FindTypesInUse): - Assistant
Only my new test — good. Waiting for the run to complete.
- Assistant
I'll wait for the background waiter (bntd900al) to notify me when the gradle run produces output.
- Assistant
Still building. I'll wait for the bntd900al waiter to fire when output appears.
- Assistant
Waiting for the test-run notification.
- Assistant
That was just the sleep timer. The main waiter (bntd900al) will notify when the gradle test run produces output.
- Assistant
Guava is on the test classpath. Let me change my repro to match the issue exactly:
- Assistant
Both tests pass, but they'd also pass trivially if the visitor never ran. Let me make the tests prove the visitor executes by including a genuinely unused import:
- Assistant
Let me examine how Javadoc trees are traversed by
JavaVisitor— a place where identifiers might be missed: - Assistant
Javadoc is covered. Let me set up a fast standalone iteration loop instead of 6-minute gradle runs:
- Assistant
Probe works — issue example produces NO CHANGES at this commit. Now let me batch-probe exotic variants:
- Assistant
Let me probe static imports of nested classes used only in parameterized form — the
staticClassespath uses different keying:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.