From 462630c9b5b813044328d44da9ce16fec1e95d5a Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Mon, 17 Sep 2018 16:29:03 +0700 Subject: [PATCH] Fixed boxed boolean handling --- .../codeInspection/dataFlow/DfaMemoryStateImpl.java | 2 +- .../inspection/dataFlow/fixture/BoxedBoolean.java | 12 ++++++++++++ .../java/codeInspection/DataFlowInspectionTest.java | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/BoxedBoolean.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index 51492ed3d322..cc51a4853546 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -911,7 +911,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { return true; } return applyRelation(unboxedLeft, unboxedRight, negated) && - checkCompareWithBooleanLiteral(unboxedLeft, unboxedRight, negated); + ((negated && !isNotNull(dfaLeft)) || checkCompareWithBooleanLiteral(unboxedLeft, unboxedRight, negated)); } private boolean checkCompareWithBooleanLiteral(DfaValue dfaLeft, DfaValue dfaRight, boolean negated) { diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/BoxedBoolean.java b/java/java-tests/testData/inspection/dataFlow/fixture/BoxedBoolean.java new file mode 100644 index 000000000000..37fa513bedb5 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/BoxedBoolean.java @@ -0,0 +1,12 @@ +import org.jetbrains.annotations.*; + +class X { + native @Nullable Boolean readSomething(); + + void test() { + final Boolean x = readSomething(); + if(x == Boolean.TRUE) {} + else if(x == Boolean.FALSE || x == null) {} + else {} + } +} \ 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 270501ff3d6f..3f45c7656541 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java @@ -648,4 +648,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase { public void testSameArguments() { doTest(); } public void testMaxLoop() { doTest(); } public void testExplicitBoxing() { doTest(); } + public void testBoxedBoolean() { doTest(); } }