IDEA-123850 incorrect "Condition is always false" warning in GemRequirementsChangeWatcher.updateAndAttach()

This commit is contained in:
peter
2014-04-12 16:38:17 +02:00
parent c6c205d5e8
commit b5df84e66b
5 changed files with 38 additions and 14 deletions
@@ -497,7 +497,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
public DfaConstValue getConstantValue(DfaVariableValue value) {
int index = getEqClassIndex(value);
EqClass ec = index == -1 ? null : myEqClasses.get(index);
return ec == null ? null : ec.findConstant(true);
return ec == null ? null : (DfaConstValue)unwrap(ec.findConstant(true));
}
@Override
@@ -818,7 +818,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
Set<DfaVariableValue> vars = ContainerUtil.newLinkedHashSet(getChangedVariables());
for (EqClass aClass : myEqClasses) {
if (aClass != null) {
vars.addAll(aClass.getVariables());
vars.addAll(aClass.getVariables(true));
}
}
for (DfaVariableValue value : vars) {
@@ -55,10 +55,12 @@ class EqClass extends SortedIntSet {
return buf.toString();
}
List<DfaVariableValue> getVariables() {
List<DfaVariableValue> getVariables(boolean unwrap) {
List<DfaVariableValue> vars = ContainerUtil.newArrayList();
for (DfaValue value : getMemberValues()) {
value = DfaMemoryStateImpl.unwrap(value);
if (unwrap) {
value = DfaMemoryStateImpl.unwrap(value);
}
if (value instanceof DfaVariableValue) {
vars.add((DfaVariableValue)value);
}
@@ -80,13 +82,10 @@ class EqClass extends SortedIntSet {
}
@Nullable
DfaConstValue findConstant(boolean wrapped) {
DfaValue findConstant(boolean wrapped) {
for (DfaValue value : getMemberValues()) {
if (wrapped) {
value = DfaMemoryStateImpl.unwrap(value);
}
if (value instanceof DfaConstValue) {
return (DfaConstValue)value;
if (value instanceof DfaConstValue || wrapped && DfaMemoryStateImpl.unwrap(value) instanceof DfaConstValue) {
return value;
}
}
return null;
@@ -255,8 +255,8 @@ class StateMerger {
result = ContainerUtil.newLinkedHashSet();
for (EqClass eqClass : state.getNonTrivialEqClasses()) {
DfaConstValue constant = eqClass.findConstant(true);
List<DfaVariableValue> vars = eqClass.getVariables();
DfaValue constant = eqClass.findConstant(true);
List<DfaVariableValue> vars = eqClass.getVariables(false);
for (DfaVariableValue var : vars) {
if (constant != null) {
result.add(Fact.createEqualityFact(var, constant, true));
@@ -270,8 +270,8 @@ class StateMerger {
}
for (UnorderedPair<EqClass> classPair : state.getDistinctClassPairs()) {
List<DfaVariableValue> vars1 = classPair.first.getVariables();
List<DfaVariableValue> vars2 = classPair.second.getVariables();
List<DfaVariableValue> vars1 = classPair.first.getVariables(false);
List<DfaVariableValue> vars2 = classPair.second.getVariables(false);
LinkedHashSet<DfaValue> firstSet = new LinkedHashSet<DfaValue>(vars1);
ContainerUtil.addIfNotNull(firstSet, classPair.first.findConstant(true));
@@ -0,0 +1,23 @@
import org.jetbrains.annotations.Nullable;
import java.util.List;
class Foo {
public static void main(@Nullable Boolean hasMissingGems, List<String> missing) {
if (hasMissingGems != null && hasMissingGems) {
return;
}
if (hasMissingGems == null && missing.size() > 0) {
}
}
public static void main2(@Nullable Boolean hasMissingGems, List<String> missing) {
if ((hasMissingGems != null && hasMissingGems) || (hasMissingGems == null && missing.size() > 0)) {
}
}
}
@@ -312,6 +312,8 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testNotNullAfterDereference() { doTest(); }
public void testNullableBoolean() { doTest(); }
public void testSameComparisonTwice() { doTest(); }
public void testParametersAreNonnullByDefault() {