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.
xml<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?
javaimport 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?
javaimport 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?
java - Assistant
Let me look at the existing tests and reproduce the issue.
- Assistant
I'll add a reproduction test first.
- Assistant
I'll wait for the background test to complete.
- Assistant
While waiting, let me check how identifiers within class type parameters are visited — particularly the
visitIdentifierskip inFindTypesInUse: - Assistant
While waiting, let me prepare additional reproduction variants covering generics-only usages:
- Assistant
I'll wait for the current build, then rerun with all three variants.
- Assistant
The build is still running. Let me wait for its completion event.
- Assistant
The build is in its configuration phase. I'll continue when it completes — the monitors will notify me.
- Assistant
I'll wait for the background task notifications instead of polling.
- Assistant
Waiting for the build to complete — the monitor will notify me with the result.
- Assistant
The build is progressing through configuration. I'll pick up as soon as a monitor event fires with the test outcome.
- Assistant
The multi-project configuration takes a few minutes. I'll resume when the monitors fire.
- Assistant
Waiting on the Gradle build — monitors are armed and will notify me when output appears and when the build finishes.
- Assistant
Waiting for build events now.
- Assistant
Waiting for the build result events.
- Assistant
Still waiting on the Gradle build; the real monitors on the build output remain armed.
- Assistant
Build is still configuring. I'll wait for the armed monitors to fire rather than poll further.
- Assistant
Waiting for build completion events.
- Assistant
I'm now idle until the build monitors report back with the test results.
- Assistant
Waiting for the Gradle build to finish — the monitors on the output file will notify me when the test results are available.
- Assistant
Waiting for configuration to progress.
- Assistant
I'll resume when the background watchers notify me.
- Assistant
Waiting on build progress notifications.
- Assistant
Waiting for the Gradle build to progress; monitors will notify me.
- Assistant
Waiting for build events.
- Assistant
Waiting for the scratch test run to complete.
- Assistant
I'll resume when the test run notification arrives.
- Assistant
Let me look at
J.Import.getTypeName()andtoFullyQualifiedNamefor$vs.handling: - Assistant
Let me build a fast iteration loop: a standalone driver using the already-compiled classes, avoiding the slow test-module recompile:
- Assistant
The driver works — seconds per iteration. Now let me generate a large batch of generics scenarios:
- Assistant
All single-file variants pass. The remaining dimension: multi-file parsing where the generic argument type comes from another source file. Let me extend the driver:
- Assistant
Let me test static imports of nested types used only in generics:
- Assistant
Let me try composite scenarios — wildcards, duplicates, static wildcard interplay:
- Assistant
Maybe the culprit is actually
OrderImports(the reporter ran both recipes). Let me check its handling: - Assistant
All pass again. New approach — fuzz against the repository's own sources (rich in generics), where any removal is suspect:
- Assistant
Real hits! Let me verify each against the actual sources:
- Assistant
Two new files changed in rewrite-core after the fix — let me inspect:
- Assistant
While tests run, check whether
JavaType.Annotationexists and flows intotypesInUse: - Assistant
JavaType.Annotationdelegates FQN methods — handled by theFullyQualifiedbranch. Now waiting for the test suite results.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.