-
Notifications
You must be signed in to change notification settings - Fork 71
org.openrewrite.staticanalysis.RemoveRedundantTypeCast
fails to consider generics correctly
#353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
org.openrewrite.staticanalysis.RemoveRedundantTypeCast
fails to consider generics correctly
We've also run into this, here's a test case that replicates what we're seeing.
@Test
void removeRedundantCast() {
rewriteRun(
spec -> spec.recipe(new RemoveRedundantTypeCast()),
// language=java
java(
"""
package com.helloworld;
import java.util.Optional;
public class Foo {
public interface Bar {}
public static class BarImpl implements Bar {}
private Bar getBar() {
return new BarImpl();
}
private BarImpl getBarImpl() {
return new BarImpl();
}
public Bar baz() {
return Optional.of((Bar) getBarImpl()).orElse(getBar());
}
}
"""));
}
} |
Thanks for the runnable report! I think this might be a slightly different case as there's no generics involved, right? Did you already explore a potential fix by running the recipe and seeing where it decides to remove the cast? |
Ah yes, you are right, my example does not concern generic. Let me know if you prefer that I open a separate ticket. I haven't debugged the recipe further. |
If you're up for it a draft PR that adds that test would be most helpful; no expectation that you'll work on a fix, but it makes it so we can easily checkout the PR locally, run and debug. 🙏🏻 |
Sorry for the slow reply, but here's a PR with the failing test case: #495 |
What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
What did you see instead?
This fails to compile because generics require an exact map on type so Map != HashMap.
The text was updated successfully, but these errors were encountered: