What is the smallest, simplest way to reproduce the problem?
java
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?
java
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?
java
Assistant
Found the root cause. Let me verify the mechanism precisely and implement the fix:
Assistant
Now let me implement the fix in RemoveUnusedImports:
Assistant
Now the usage in the non-static branch:
Assistant
Now add the helper methods:
Assistant
Now add the check at the top of the import loop:
Assistant
Now let me run my verification tests plus a broader scan again with this restructured version:
Assistant
All checks are complete. Here is my review of the checklist:
1. If an error was reported in the issue description, I have successfully reproduced it.
Yes. The reported snippet only misbehaves when the generic type cannot be resolved on the parser classpath (the reporter's real project). With a harness I showed that for
parsed without guava, only contains and removed . The precondition does not protect the source, because tolerates a missing type on the identifier of a (whereas the same reference generics, e.g. , is reported, and the import is retained — hence "in Generics only").
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
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?
Since you are given a git repository, you can use git commands to simplify your work.
For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state.
You can also reset all changes in the repository using git reset --hard command.
Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later.
Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands.
However you don't need to use git add or git commit before submitting your changes. In fact,
submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.
CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
If an error was reported in the issue description, I have successfully reproduced it.
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
I have thought about edge cases and made sure my fix handles them as well.
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /rewrite, current file: none) bash-$
public class BloomFilterRef<T> extends AtomicReference<BloomFilter<T>>
getTypesInUse()
AtomicReference<{undefined}>
RemoveUnusedImports
import com.google.common.hash.BloomFilter;
NoMissingTypes
FindMissingTypes
clazz
J.ParameterizedType
without
extends BloomFilter
2. If an error was reported in the issue description, I have confirmed that my fix resolves the error.
Yes. RemoveUnusedImports now collects the simple names used by generic type references that lack type attribution and keeps imports that could satisfy them. Verified: the issue snippet is left unchanged with default type validation, with TypeValidation.none(), through OrderImports(removeUnused = true), and it still is a no-op when the type is resolvable.
3. I have thought about edge cases and made sure my fix handles them as well.
Covered variants (all retain the import now, previously several were stripped): extends/implements/field/method/local/cast/bound positions, nested and deeply nested type arguments, qualified Outer.Inner<T> (FieldAccess clazz), static imports of nested generic types, and star imports (kept unfolded/untouched while unknown generics exist). Conversely, unrelated genuinely-unused imports are still removed, even in files containing unresolved generics, and fully typed sources behave exactly as before (no extra retention, no recipe cycles).
4. I have run existing tests in the repository that might have been affected.:rewrite-java-test:test (2115 tests), :rewrite-java:test (640), :rewrite-groovy:test (646) all pass with 0 failures; :rewrite-kotlin:test (1228) also passed. Pre-existing, unrelated environment problems: rewrite-scala:compileScala fails on US-ASCII encoding, and one rewrite-maven test fails on an HTTP 401 from a remote repository (both independent of my change; rewrite-gradle tests pass when re-run). I did not add or modify any tests, per the instructions; all scratch files used for investigation were deleted.