Skip to content

Commit

Permalink
simplify dataflow update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Sep 30, 2024
1 parent f98fb3c commit fa7728e
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,12 @@ public NullnessHint onDataflowVisitMethodInvocation(

Set<String> fieldNames = getAnnotationValueArray(methodSymbol, annotName, false);
if (fieldNames != null) {
boolean trueIfNonNull = getResultValueFromAnnotation(methodSymbol);
fieldNames = ContractUtils.trimReceivers(fieldNames);
boolean trueIfNonNull = getResultValueFromAnnotation(methodSymbol);
// chosenUpdates is set to the thenUpdates or elseUpdates appropriately given the annotation's
// result value
AccessPathNullnessPropagation.Updates chosenUpdates =
trueIfNonNull ? thenUpdates : elseUpdates;
for (String fieldName : fieldNames) {
VariableElement field =
getInstanceFieldOfClass(
Expand All @@ -306,11 +310,10 @@ public NullnessHint onDataflowVisitMethodInvocation(
continue;
}

// The call to the EnsuresNonNullIf method ensures that the field is then not null
// (or null, depending on the result flag) at this point.
// The call to the EnsuresNonNullIf method ensures that the field is not null in the chosen
// updates.
// In here, we assume that the annotated method is already validated.
thenUpdates.set(accessPath, trueIfNonNull ? Nullness.NONNULL : Nullness.NULL);
elseUpdates.set(accessPath, trueIfNonNull ? Nullness.NULL : Nullness.NONNULL);
chosenUpdates.set(accessPath, Nullness.NONNULL);
}
}

Expand Down

0 comments on commit fa7728e

Please sign in to comment.