Flush canonicalized variable if requested one not found

Fixes IDEA-207441 False-positive "variable is always null" on linked-list like data structure
This commit is contained in:
Tagir Valeev
2019-02-20 16:36:40 +07:00
parent 7de1dff527
commit 8aa936dc00
3 changed files with 52 additions and 1 deletions
@@ -1530,7 +1530,12 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
private void removeEquivalence(DfaValue var) {
int varID = var.getID();
Integer varClassIndex = myIdToEqClassesIndices.get(varID);
if (varClassIndex == null) return;
if (varClassIndex == null) {
var = canonicalize(var);
varID = var.getID();
varClassIndex = myIdToEqClassesIndices.get(varID);
if (varClassIndex == null) return;
}
EqClass varClass = myEqClasses.get(varClassIndex);
@@ -0,0 +1,45 @@
import org.jetbrains.annotations.Nullable;
class IntHashMap {
public void minTest() {
initEntries();
for (Entry entry : table) {
if (entry != null) {
Entry tmp = entry;
Entry tmpNext;
while (tmp != null) {
tmpNext = tmp.next;
tmp.next = null;
tmp = tmpNext;
System.out.println("tmpNext " + ((tmpNext == null) ? "is null" : "is not null"));
}
}
}
}
private Entry[] table = new Entry[16];
private class Entry {
@Nullable Entry next;
}
private void initEntries() {
table[0] = new Entry();
table[0].next = new Entry();
table[1] = new Entry();
table[3] = new Entry();
table[5] = new Entry();
table[5].next = new Entry();
}
public static void main(String[] args) {
IntHashMap map = new IntHashMap();
map.minTest();
}
}
@@ -214,6 +214,7 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
public void testPrimitiveGetters() { doTest(); }
public void testUnknownOnStack() { doTest(); }
public void testMapUpdateInlining() { doTestWithCustomAnnotations(); }
public void testHashMapImplementation() { doTest(); }
public void testOptionalTooComplex() { doTest(); }