rewrite-static-analysis
rewrite-static-analysis copied to clipboard
`org.openrewrite.staticanalysis.RemoveRedundantTypeCast` fails to consider generics correctly
What is the smallest, simplest way to reproduce the problem?
class A {
void foo() {
var a = new HashMap<String, String>();
Optional.of((Map<String, Object>)a)
.filter(Predicate.not(Map::isEmpty));
}
}
What did you expect to see?
class A {
void foo() {
var a = new HashMap<String, String>();
Optional.of((Map<String, Object>)a)
.filter(Predicate.not(Map::isEmpty));
}
}
What did you see instead?
class A {
void foo() {
var a = new HashMap<String, String>();
Optional.of(a)
.filter(Predicate.not(Map::isEmpty));
}
}
This fails to compile because generics require an exact map on type so Map != HashMap.