rewrite-static-analysis
rewrite-static-analysis copied to clipboard
`InstanceOfPatternMatch` declares variable with conflicting name
The InstanceOfPatternMatch declares a pattern variable with a conflicting name if a variable with that name already exists in the if body after the corresponding type cast as in the following example:
void test(Object o) {
if (o instanceof String) {
System.out.println((String) o);
String string = "x";
}
}
Currently the recipe will change this to the following illegal code:
void test(Object o) {
if (o instanceof String string) {
System.out.println(string);
String string = "x";
}
}
Fixing openrewrite/rewrite#2776 should address this issue and the corresponding test case can be enabled again.
- openrewrite/rewrite#2776