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
I’ll trace
RemoveUnusedImportsand its generic type-usage attribution, add a focused regression test, then run the narrow Java test suite and adjust the implementation. - Assistant
The current implementation already contains newer safeguards around source identifiers and parameterized type arguments, so I’m checking whether the reported case is covered or whether nested generic attribution still falls through. I’ll pin this down with a test using an in-memory dependency type, avoiding any network dependency.
- Assistant
The exact reported inheritance shape is now under test. The build is still compiling the Java test modules; once it completes, I’ll use the AST/type evidence from the failure (if any) to make the smallest safe change.
- Assistant
The first Gradle configuration is unusually slow but remains active; it has moved through
buildSrcwithout errors. I’m letting the focused test finish rather than broadening the build, and I’m also checking whether the test task is waiting on compilation or dependency resolution. - Assistant
The repository’s latest code already preserves the simple reported case through an unqualified-reference fallback. I found a remaining weakness in the underlying generic-type collection: it only descends one generic level. I’m tightening that collection recursively, which makes the fix structural and covers the reported case plus nested generic arguments without weakening unused-import removal.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.