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
I’ll trace
RemoveUnusedImports, add the smallest regression test for a type used only as a generic argument, then fix and run the focused Java tests. - Assistant
rgisn’t installed in this checkout, so I’m usingfind/grepfor the repository inspection and keeping the scope to the Java module. - Assistant
The regression test is in place and the focused Gradle run is compiling the module. I’m also checking whether the failure comes from nested
JavaType.Parameterizedattribution, which the current type collection only traverses one level deep. - Assistant
Compilation is unusually quiet but still active; there’s no test result yet. Once it completes, I’ll use the exact failing assertion to keep the implementation change narrow.
- Assistant
The first Gradle attempt tried to resolve dynamic build metadata remotely, which is outside this task’s offline constraint. I’m stopping that attempt and rerunning from the local dependency cache in offline mode.
- Assistant
The exact synthetic reproduction is already unchanged under the current parser, so I’m tightening it to the reported Guava-attributed type rather than assuming the stub is equivalent. This will distinguish a parser-attribution edge case from a general nested-generic traversal bug.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.