IDEA-218212 ConstantConditions incorrectly determines when collection is empty or not

GitOrigin-RevId: 2bdcfb4957026ad83b3e54925f20c0133d29d6c6
This commit is contained in:
Tagir Valeev
2019-07-16 09:03:31 +03:00
committed by intellij-monorepo-bot
parent d93e5a3b81
commit 90c6f0b17d
3 changed files with 21 additions and 0 deletions
@@ -172,6 +172,13 @@ public class StandardInstructionVisitor extends InstructionVisitor {
if (arrayElementValue != DfaUnknownValue.getInstance()) {
result = arrayElementValue;
}
if (!(result instanceof DfaVariableValue) && array instanceof DfaVariableValue) {
for (DfaVariableValue value : ((DfaVariableValue)array).getDependentVariables().toArray(new DfaVariableValue[0])) {
if (value.getQualifier() == array) {
dropLocality(value, memState);
}
}
}
pushExpressionResult(result, instruction, memState);
return nextInstruction(instruction, runner, memState);
}
@@ -0,0 +1,13 @@
import java.util.Collection;
import java.util.ArrayList;
class X {
public static void main(String[] args) {
Collection<Integer>[] a = new Collection[2];
for (int t = 0; t < 2; t++) a[t] = new ArrayList<>();
for (int i = 0; i < 4; i++) a[i % 2].add(i);
if (a[0].isEmpty() || a[1].isEmpty()) {
System.out.println("never happens");
}
}
}
@@ -663,4 +663,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testNullableTernaryInConstructor() { doTest(); }
public void testEqualityLongInteger() { doTest(); }
public void testFieldRewrittenInInner() { doTest(); }
public void testArrayElementLocality() { doTest(); }
}