mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix dfa contract believing that nullable is always null
This commit is contained in:
+5
-2
@@ -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 &&
|
||||
|
||||
+16
@@ -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(); }
|
||||
|
||||
Reference in New Issue
Block a user