Remove redundant null check for instanceof patterns#383
Conversation
|
Have marked this as Draft again. This is really not an ideal solution; ideally What do you think? Though after all, the null-check is not 'incorrect' (and is probably side-effect free); it is just redundant. So I could understand if you decide to keep it as it is and close this PR unmerged. Even with the changes of this PR this will only remove the null-check if an class InstanceOfTest {
int m(Object o1, Object o2) {
if (!(o1 instanceof String s1 && o2 instanceof String s2)) {
return 1;
}
return 0;
}
}Decompiled: if (!(object instanceof String) || null == (string = (String)object) || !(object2 instanceof String)) { |
|
Hey - I have a fairly large pipeline change which is continuing to improve most of this, will look again after merged. |
|
we're good now (Added this as an explicit test) |
CondenseConditionals#condenseInstanceOfAssignintroduces a redundant null-check (apparently to lift the assignment into theifcondition?) which ends up in the decompiled output:cfr/src/org/benf/cfr/reader/bytecode/analysis/opgraph/op3rewriters/CondenseConditionals.java
Lines 506 to 509 in a0d8fbf
This PR here tries to detect that and remove it again.
Example (JDK 21):
Decompiled: