IDEA-90613 Invalid @Nullable processing

This commit is contained in:
peter
2012-09-07 19:08:41 +02:00
parent b0428ec975
commit 316e41c33b
3 changed files with 35 additions and 6 deletions
@@ -274,12 +274,8 @@ public class StandardInstructionVisitor extends InstructionVisitor {
final DfaMemoryState trueCopy = memState.createCopy();
if (trueCopy.applyCondition(dfaRelation)) {
if (dfaLeft instanceof DfaVariableValue && dfaRight instanceof DfaVariableValue) {
if (trueCopy.isNotNull((DfaVariableValue)dfaLeft)) {
trueCopy.applyCondition(relationFactory.create(dfaRight, factory.getConstFactory().getNull(), JavaTokenType.EQEQ, true));
} else if (trueCopy.isNotNull((DfaVariableValue)dfaRight)) {
trueCopy.applyCondition(relationFactory.create(dfaLeft, factory.getConstFactory().getNull(), JavaTokenType.EQEQ, true));
}
if (!dfaRelation.isNegated()) {
handleEqualVariables(dfaRight, dfaLeft, factory, trueCopy);
}
trueCopy.push(factory.getConstFactory().getTrue());
instruction.setTrueReachable();
@@ -335,6 +331,17 @@ public class StandardInstructionVisitor extends InstructionVisitor {
return nextInstruction(instruction, runner, memState);
}
private static void handleEqualVariables(DfaValue var1, DfaValue var2, DfaValueFactory factory, DfaMemoryState state) {
if (!(var2 instanceof DfaVariableValue) || !(var1 instanceof DfaVariableValue)) {
return;
}
DfaValue nowNotNull = state.isNotNull((DfaVariableValue)var2) ? var1 : state.isNotNull((DfaVariableValue)var1) ? var2 : null;
if (nowNotNull != null) {
state.applyCondition(factory.getRelationFactory().create(nowNotNull, factory.getConstFactory().getNull(), JavaTokenType.EQEQ, true));
}
}
public boolean isInstanceofRedundant(InstanceofInstruction instruction) {
return !myUsefulInstanceofs.contains(instruction) && !instruction.isConditionConst() && myReachable.contains(instruction);
}
@@ -0,0 +1,21 @@
import org.jetbrains.annotations.Nullable;
class TestIDEAWarn {
void test(java.util.Map<Object, Object> values) {
boolean condition = false;
Object target = getTarget();
for (Object o : values.values()) {
if (o != null && o != target) {
condition = true;
}
}
if (!condition || target == null) {
System.out.println(target);
}
}
@Nullable
public Object getTarget() {
return null;
}
}
@@ -72,5 +72,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
public void testEqualsNotNull() throws Throwable { doTest(); }
public void testVisitFinallyOnce() throws Throwable { doTest(); }
public void testNotEqualsDoesntImplyNotNullity() throws Throwable { doTest(); }
}