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 accounting, add a focused regression test for this inheritance case, then run the narrow Java test suite and adjust the implementation. - Assistant
The regression sits in the newer “source identifier” safeguard: a generic type reference can be represented by
J.ParameterizedType, so collecting only identifiers is too narrow. I’m first locking the reported Guava case into the existing recipe tests, then I’ll change the source-reference check at the AST type-use level. - Assistant
The focused test is still in Gradle’s configuration/compilation phase without output; while it runs, I’m inspecting the relevant AST node shapes so the fix remains narrow and doesn’t undo the static-import attribution safeguard.
- Assistant
Compilation of the changed Java module succeeds. The full focused test cannot start in this checkout’s offline environment because several test-runtime artifacts are absent, so I’m tightening the implementation around the actual invariant: every raw type nested in a parameterized type must be registered, recursively, instead of relying on one-level type attribution.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.