From dea8248bfe7bea67b12fbee9718738e1136dbfa7 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 26 Sep 2013 17:41:52 +0200 Subject: [PATCH] dfa: if a variable is not nullable-enabled, don't make it such --- .../codeInspection/dataFlow/StateMerger.java | 2 +- .../dataFlow/fixture/VariablesDiverge.java | 18 ++++++++++++++++++ .../codeInspection/DataFlowInspectionTest.java | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/VariablesDiverge.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java index e886dde637a0..658b2d2123ed 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java @@ -79,7 +79,7 @@ class StateMerger { for (DfaVariableValue unknownVar : removedState.getUnknownVariables()) { copy.doFlush(unknownVar, true); } - if (removedState.isNull(var)) { + if (removedState.getVariableState(var).isNullable()) { copy.setVariableState(var, copy.getVariableState(var).withNullability(Nullness.NULLABLE)); } } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/VariablesDiverge.java b/java/java-tests/testData/inspection/dataFlow/fixture/VariablesDiverge.java new file mode 100644 index 000000000000..f07fffb6a8a1 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/VariablesDiverge.java @@ -0,0 +1,18 @@ +import java.io.File; + +class Some { + private void findRepository(File file, boolean b) { + System.out.println(file.getName()); + if (b) { + File parent = file; + while (parent != null) { + parent = parent.getParentFile(); + } + System.out.println(parent.getName()); + } + System.out.println(file.getName()); + } + +} + + diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index cc9dee3d26aa..55dd5cce11e1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -302,6 +302,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testManySequentialIfsNotComplex() { doTest(); } public void testLongDisjunctionsNotComplex() { doTest(); } public void testWhileNotComplex() { doTest(); } + public void testVariablesDiverge() { doTest(); } public void _testNullCheckBeforeInstanceof() { doTest(); } }