mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-90613 Invalid @Nullable processing
This commit is contained in:
+13
-6
@@ -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);
|
||||
}
|
||||
|
||||
+21
@@ -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(); }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user