[java-dfa] Fix ephemeral states on comparison

GitOrigin-RevId: cd7fde86062bcda7145dae7b98c661a64fbccb9d
This commit is contained in:
Tagir Valeev
2021-04-23 05:28:33 +03:00
committed by intellij-monorepo-bot
parent ca58327e44
commit ad22cd9a74
3 changed files with 20 additions and 7 deletions
@@ -715,6 +715,11 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
if (DfaTypeValue.isUnknown(dfaLeft) || DfaTypeValue.isUnknown(dfaRight)) return true;
if (relationType == RelationType.EQ && dfaLeft instanceof DfaVariableValue && dfaRight instanceof DfaVariableValue) {
checkEphemeral(dfaLeft, dfaRight);
checkEphemeral(dfaRight, dfaLeft);
}
DfType leftType = getDfType(dfaLeft);
DfType rightType = getDfType(dfaRight);
@@ -877,13 +882,8 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
return true;
}
if (type == RelationType.EQ) {
if (dfaLeft instanceof DfaVariableValue && dfaRight instanceof DfaVariableValue) {
checkEphemeral(dfaLeft, dfaRight);
checkEphemeral(dfaRight, dfaLeft);
}
if (!applySpecialFieldEquivalence(dfaLeft, dfaRight)) return false;
}
if (type == RelationType.EQ && !applySpecialFieldEquivalence(dfaLeft, dfaRight)) return false;
if (dfaLeft instanceof DfaVariableValue && dfaRight instanceof DfaVariableValue && !isNegated) {
if (!equalizeTypesOnGetClass((DfaVariableValue)dfaLeft, (DfaVariableValue)dfaRight)) {
return false;
@@ -0,0 +1,12 @@
import java.util.Set;
public class UnknownComparedToNullable {
native Object getObject(int x);
void test(int val) {
Object s1 = val < 0 ? null : getObject(val * 2);
Object s2 = getObject(val);
if (s1 != s2) {}
System.out.println(s2.hashCode());
}
}
@@ -696,4 +696,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testCollectionViewsSize() { doTest(); }
public void testFlushedNullableOnUnknownCall() { doTest(); }
public void testBoxedDivisionComparison() { doTest(); }
public void testUnknownComparedToNullable() { doTest(); }
}