DfaMemoryStateImpl#applyUnboxedRelation: NPE fixed on erroneous code (EA-137969)

This commit is contained in:
Tagir Valeev
2019-02-27 10:41:56 +07:00
parent 256eefe706
commit 145a513d7b
4 changed files with 13 additions and 8 deletions
@@ -1137,7 +1137,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
DfaConstValue leftConst = getConstantValue(unboxedLeft);
DfaConstValue rightConst = getConstantValue(unboxedRight);
if (leftConst != null && rightConst != null) {
return leftConst.getValue().equals(rightConst.getValue()) != negated;
return Objects.equals(leftConst.getValue(), rightConst.getValue()) != negated;
}
if (negated && (PsiType.FLOAT.equals(unboxedLeft.getType()) || PsiType.DOUBLE.equals(unboxedLeft.getType()))) {
// If floating point wrappers are not equal, unboxed versions could still be equal if they are 0.0 and -0.0
@@ -61,13 +61,12 @@ public class DfaBinOpValue extends DfaValue {
@Override
public String toString() {
String delimiter;
if (myOp == BinOp.PLUS && myRight instanceof DfaConstValue &&
((DfaConstValue)myRight).getValue() instanceof Long &&
(Long)((DfaConstValue)myRight).getValue() < 0) {
delimiter = "";
} else {
delimiter = myOp.toString();
String delimiter = myOp.toString();
if (myOp == BinOp.PLUS && myRight instanceof DfaConstValue) {
Object value = ((DfaConstValue)myRight).getValue();
if (value instanceof Long && (Long)value < 0) {
delimiter = "";
}
}
return myLeft + delimiter + myRight;
}
@@ -175,6 +175,7 @@ public class DfaConstValue extends DfaValue {
return myType;
}
@Nullable
public Object getValue() {
return myValue;
}
@@ -16,4 +16,9 @@ class Testcase {
}
}
void test() {
<error descr="Incompatible types. Found: 'null', required: 'int'">int x = null;</error>
Integer boxed = x;
if (<warning descr="Condition 'boxed == 5' is always 'false'">boxed == 5</warning>) {}
}
}