rewrite-static-analysis icon indicating copy to clipboard operation
rewrite-static-analysis copied to clipboard

`org.openrewrite.staticanalysis.RemoveRedundantTypeCast` fails to consider generics correctly

Open blipper opened this issue 4 months ago • 0 comments

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.

blipper avatar Oct 03 '24 02:10 blipper