fix dfa when a notnull parameter is assigned to null

This commit is contained in:
peter
2017-02-27 14:04:04 +01:00
parent 84cd1dd65e
commit 38776ed827
2 changed files with 18 additions and 2 deletions
@@ -268,9 +268,8 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
return;
}
setVariableState(var, getVariableState(var).withValue(value));
setVariableState(var, withValueNullability(value, getVariableState(var).withValue(value)));
if (value instanceof DfaTypeValue) {
setVariableState(var, getVariableState(var).withNullability(((DfaTypeValue)value).getNullness()));
DfaRelationValue dfaInstanceof = myFactory.getRelationFactory().createRelation(var, value, JavaTokenType.INSTANCEOF_KEYWORD, false);
if (((DfaTypeValue)value).isNotNull()) {
applyCondition(dfaInstanceof);
@@ -293,6 +292,12 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
}
}
private DfaVariableState withValueNullability(DfaValue value, DfaVariableState state) {
if (value instanceof DfaTypeValue) return state.withNullability(((DfaTypeValue)value).getNullness());
if (isNull(value)) return state.withNullability(Nullness.NULLABLE);
return state;
}
private DfaValue handleFlush(DfaVariableValue flushed, DfaValue value) {
if (value instanceof DfaVariableValue && (value == flushed || myFactory.getVarFactory().getAllQualifiedBy(flushed).contains(value))) {
Nullness nullability = isNotNull(value) ? Nullness.NOT_NULL : ((DfaVariableValue)value).getInherentNullability();
@@ -2,6 +2,7 @@ import org.jetbrains.annotations.*;
class Test {
/*
@Nullable
String findMessage(@NotNull Element element) {
while (element != null) {
@@ -23,6 +24,16 @@ class Test {
}
return null;
}
*/
void foo(@NotNull String param) {
if (equals(3)) {
param = null;
}
if (param != null) {
System.out.println();
}
}
}