RemoveUnusedPrivateMethods removes private method still called with raw collection arguments
What version of OpenRewrite are you using?
- rewrite-static-analysis: 2.34.0
- rewrite-core: 8.81.1
- rewrite-java: 8.81.1
What is the smallest, simplest way to reproduce the problem?
This is an edge case involving raw collection arguments. The raw Map is important here; a parameterized Map<String, String> does not reproduce the issue.
import java.util.Collection;
import java.util.Map;
import java.util.Set;
class Main {
Main(Map templates) {
compileTemplates(templates.keySet(), templates.values());
}
private Set<String> compileTemplates(
final Set<String> compiledParam, final Collection<String> toCheck) {
return compiledParam;
}
}
Run org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods.
What did you expect to see?
The private compileTemplates(..) method should be preserved because it is called from the constructor.
Although the call uses raw Map#keySet() and Map#values() values, the original code compiles with unchecked/rawtype warnings.
What did you see instead?
The recipe removes the private method and its imports, but leaves the call site behind:
import java.util.Map;
class Main {
Main(Map templates) {
compileTemplates(templates.keySet(), templates.values());
}
}
The rewritten code no longer compiles because compileTemplates(..) no longer exists.
“I’d like to work on this. I’ll investigate and submit a PR.”