From d7fba34d4c3853dcfa6fe784275fad8fab3ecd7f Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Thu, 11 Jan 2018 10:21:08 +0700 Subject: [PATCH] Revert incorrect fixes for IDEA-184723 Data flow algorithm complexity This reverts commits 9a837e70d3a98dc6883590167fbb1ef0a60b2b5a and 6d52b5462e53ae628ea5b796c0110b508c853b36. --- .../codeInspection/dataFlow/StateMerger.java | 4 -- .../dataFlow/fixture/NullabilityBasics.java | 31 ------------ .../dataFlow/fixture/OptionalTooComplex.java | 48 ------------------- .../DataFlowInspection8Test.java | 2 - .../DataFlowInspectionTest.java | 1 - 5 files changed, 86 deletions(-) delete mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/NullabilityBasics.java delete mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/OptionalTooComplex.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 0f8932dd6ecf..7df042704c05 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 @@ -665,10 +665,6 @@ class StateMerger { @Override void removeFromState(@NotNull DfaMemoryStateImpl state) { - if(!myPositive && state.isNotNull(myVar) && state.isNull(myArg)) { - // merging "x == null" and "x != null" should be possible with marking "x" as nullable - state.forceVariableFact(myVar, CAN_BE_NULL, true); - } state.removeEquivalenceRelations(myVar); } } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/NullabilityBasics.java b/java/java-tests/testData/inspection/dataFlow/fixture/NullabilityBasics.java deleted file mode 100644 index 25dbaf2f37c1..000000000000 --- a/java/java-tests/testData/inspection/dataFlow/fixture/NullabilityBasics.java +++ /dev/null @@ -1,31 +0,0 @@ -import org.jetbrains.annotations.*; - -class NullabilityBasics { - - void test2() { - String x = getNullable(); - if (x == null) { - System.out.println("x is null!"); - } - if (isEmpty(x) && Math.random() > 0.5) { - return; - } - System.out.println(x.trim()); - } - - @Nullable String getNullable() { - return Math.random() > 0.5 ? null : ""; - } - - @Contract(value = "null -> true",pure = true) - static boolean isEmpty(@Nullable String s) { - return s == null || s.isEmpty(); - } - - void test(String x) { - if (x == null) { - System.out.println("x is null!"); - } - System.out.println(x.trim()); - } -} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/OptionalTooComplex.java b/java/java-tests/testData/inspection/dataFlow/fixture/OptionalTooComplex.java deleted file mode 100644 index 0beb16c50f15..000000000000 --- a/java/java-tests/testData/inspection/dataFlow/fixture/OptionalTooComplex.java +++ /dev/null @@ -1,48 +0,0 @@ -import java.util.Optional; - -// IDEA-184723 -class OptionalTooComplex { - // Should not be too complex - public Long fetch() { - final PreparedStatement ps = builder - .setInteger(opt().orElse(null)) - .setInteger(opt().orElse(null)) - .setInteger(opt().orElse(null)) - .setInteger(opt().orElse(null)) - .setInteger(opt().orElse(null)) - .build(); - - ResultSet rs = null; - try { - rs = ps.executeQuery(); - if (rs.next()) { - return rs.getLong(); - } - } catch (final Exception e) { - throw new RuntimeException(e); - } finally { - } - - return 0L; - } - - interface ResultSet { - boolean next() throws Exception; - - long getLong() throws Exception; - } - - interface PreparedStatement { - ResultSet executeQuery() throws Exception; - } - - native Optional opt(); - - interface QueryBuilder { - QueryBuilder setInteger(Integer value); - - PreparedStatement build(); - } - - QueryBuilder builder; -} diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection8Test.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection8Test.java index 6777aa2d2c29..94bdd47b19e8 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection8Test.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection8Test.java @@ -220,6 +220,4 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase { public void testPrimitiveGetters() { doTest(); } public void testUnknownOnStack() { doTest(); } public void testMapUpdateInlining() { doTestWithCustomAnnotations(); } - - public void testOptionalTooComplex() { doTest(); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java index bf758fbb0076..72d122a81038 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java @@ -582,6 +582,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase { public void testPrimitiveNull() { doTest(); } public void testLessThanRelations() { doTest(); } public void testAdvancedArrayAccess() { doTest(); } - public void testNullabilityBasics() { doTest(); } public void testNullableGetterInLoop() { doTest(); } }