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
RemoveUnusedImports’ type-usage accounting, add a focused regression test for nested generic type arguments, then run the narrow Java test suite and adjust the implementation. - Assistant
rgisn’t installed in this checkout, so I’m usingfind/grepfor the same repository inspection. - Assistant
The current implementation already inspects one level of parameterized arguments, but the reported shape needs a regression test against an attributed external type. I’m adding that exact Guava case first to determine whether the remaining gap is deeper recursion or identifier attribution.
- Assistant
The focused Gradle test is still compiling the Java modules; there’s no failure output yet. While it runs, the likely correctness issue is that usage collection only descends one generic level, so I’ll verify both the exact report and nested generic arguments before changing production code.
- Assistant
Offline dependency resolution is missing a cached dynamic SLF4J listing for the Java 21 parser module. I’m keeping verification local/offline and temporarily excluding that optional test runtime module from the test project; this won’t be part of the final changes.
- Assistant
The implementation now recursively records types inside parameterized arguments (including nested parameterized types, arrays, and generic bounds) with identity-based cycle protection. Production and regression-test sources compile successfully offline; I’m doing the final formatting/diff checks now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.