diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java index 8c9c635ada33..e66ce1831927 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java @@ -245,7 +245,6 @@ public class StandardInstructionVisitor extends InstructionVisitor { DfaConstValue.Factory constFactory = factory.getConstFactory(); List falseStates = ContainerUtil.newArrayList(); for (int i = 0; i < argValues.length; i++) { - List 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 nextStates = ContainerUtil.newArrayList(); for (DfaMemoryState state : states) { boolean unknownVsNull = expectedValue == constFactory.getNull() && argValue instanceof DfaVariableValue && diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ContractInapplicableComparison.java b/java/java-tests/testData/inspection/dataFlow/fixture/ContractInapplicableComparison.java new file mode 100644 index 000000000000..92a63013e3c2 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ContractInapplicableComparison.java @@ -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; } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index af0f2a7bc2cf..67987b3ab8eb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -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(); }