fix dfa contract believing that nullable is always null

This commit is contained in:
peter
2014-05-29 21:55:46 +02:00
parent 9c29b9548a
commit a30a74e846
3 changed files with 22 additions and 2 deletions
@@ -245,7 +245,6 @@ public class StandardInstructionVisitor extends InstructionVisitor {
DfaConstValue.Factory constFactory = factory.getConstFactory();
List<DfaMemoryState> falseStates = ContainerUtil.newArrayList();
for (int i = 0; i < argValues.length; i++) {
List<DfaMemoryState> nextStates = ContainerUtil.newArrayList();
DfaValue argValue = argValues[i];
MethodContract.ValueConstraint constraint = contract.arguments[i];
DfaConstValue expectedValue = constraint == NULL_VALUE || constraint == NOT_NULL_VALUE ? constFactory.getNull() :
@@ -257,10 +256,14 @@ public class StandardInstructionVisitor extends InstructionVisitor {
boolean invertCondition = constraint == NOT_NULL_VALUE;
DfaValue condition = factory.getRelationFactory().createRelation(argValue, expectedValue, EQEQ, invertCondition);
if (condition == null) {
if (!(argValue instanceof DfaConstValue)) continue;
if (!(argValue instanceof DfaConstValue)) {
falseStates.addAll(states);
continue;
}
condition = constFactory.createFromValue(argValue == expectedValue, PsiType.BOOLEAN, null);
}
List<DfaMemoryState> nextStates = ContainerUtil.newArrayList();
for (DfaMemoryState state : states) {
boolean unknownVsNull = expectedValue == constFactory.getNull() &&
argValue instanceof DfaVariableValue &&
@@ -0,0 +1,16 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
class Foo {
void foo() {
Object o1 = bar(goo());
if (o1 == null) {
System.out.println();
}
}
@Nullable Object goo() { return null;}
@Nullable @Contract("null->null") static Object bar(@Nullable Object foo) { return foo; }
}
@@ -207,6 +207,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
}
public void testContractAnnotation() { doTest(); }
public void testContractInapplicableComparison() { doTest(); }
public void testContractInLoopNotTooComplex() { doTest(); }
public void testContractWithNullable() { doTest(); }
public void testContractWithNotNull() { doTest(); }