From c7d8ad340185586423ad17c08d6acc2a2fdab7f7 Mon Sep 17 00:00:00 2001 From: Pavel Dolgov Date: Mon, 15 May 2017 12:20:03 +0300 Subject: [PATCH] Java: Don't reuse cached ControlFlow when the context is not equivalent (IDEA-168768) --- .../psi/controlFlow/ControlFlowFactory.java | 2 +- .../advHighlighting/IDEA168768.java | 35 +++++++++++++++++++ .../daemon/LightAdvHighlightingTest.java | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEA168768.java diff --git a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java index 01121e215152..32615f15d74d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java +++ b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowFactory.java @@ -95,7 +95,7 @@ public class ControlFlowFactory { if (enableShortCircuit != this.enableShortCircuit) return false; // optimization: when no constant condition were computed, both control flows are the same - if (!controlFlow.isConstantConditionOccurred()) return true; + if (this.evaluateConstantIfCondition && !controlFlow.isConstantConditionOccurred()) return true; return evaluateConstantIfCondition == this.evaluateConstantIfCondition; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEA168768.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEA168768.java new file mode 100644 index 000000000000..eec622162d17 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEA168768.java @@ -0,0 +1,35 @@ +public class IDEA168768 { + private final boolean b = false; + private boolean b2 = false; + + public void m() throws Exception { + final long s; + if (b) { + s = 1; + } + if (b) { + System.out.println(s); + } + } + + public void m1() throws Exception { + final long s; + final boolean b1 = false; + if (b1) { + s = 1; + } + if (b1) { + System.out.println(s); + } + } + + public void m2() throws Exception { + final long s; + if (b2) { + s = 1; + } + if (b2) { + System.out.println(s); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java index 75c4e3d6f642..1b39820a7927 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java @@ -415,6 +415,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { public void testInnerClassObjectLiteralFromSuperExpression() { doTest(false); } public void testPrivateFieldInSuperClass() { doTest(false); } public void testNoEnclosingInstanceWhenStaticNestedInheritsFromContainingClass() { doTest(false); } + public void testIDEA168768() { doTest(false); } public void testStaticMethodCalls() { doTestFile(BASE_PATH + "/" + getTestName(false) + ".java").checkSymbolNames().test();