mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 10:07:41 +07:00
IDEA-69573 ConstantConditions - Warn when reading a variable that is guaranteed to be null
This commit is contained in:
+20
-4
@@ -541,6 +541,19 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public DfaConstValue getConstantValue(DfaVariableValue value) {
|
||||
DfaConstValue result = null;
|
||||
for (DfaValue equal : getEqClassesFor(value)) {
|
||||
if (equal == value) continue;
|
||||
DfaConstValue constValue = asConstantValue(equal);
|
||||
if (constValue == null) return null;
|
||||
result = constValue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyInstanceofOrNull(DfaRelationValue dfaCond) {
|
||||
DfaValue left = dfaCond.getLeftOperand();
|
||||
@@ -886,13 +899,16 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
myVariableStates.remove(varNegated);
|
||||
}
|
||||
|
||||
@Nullable private static DfaConstValue asConstantValue(DfaValue value) {
|
||||
if (value instanceof DfaConstValue) return (DfaConstValue)value;
|
||||
if (value instanceof DfaBoxedValue && ((DfaBoxedValue)value).getWrappedValue() instanceof DfaConstValue) return (DfaConstValue)((DfaBoxedValue)value).getWrappedValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean containsConstantsOnly(int id) {
|
||||
SortedIntSet varClass = myEqClasses.get(id);
|
||||
for (int i = 0; i < varClass.size(); i++) {
|
||||
int cl = varClass.get(i);
|
||||
DfaValue value = myFactory.getValue(cl);
|
||||
if (!(value instanceof DfaConstValue) &&
|
||||
!(value instanceof DfaBoxedValue && ((DfaBoxedValue)value).getWrappedValue() instanceof DfaConstValue)) {
|
||||
if (asConstantValue(myFactory.getValue(varClass.get(i))) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user