From fa7728e140e0557b327cd86961be7f3a8d9ae37f Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 30 Sep 2024 15:23:29 -0700 Subject: [PATCH] simplify dataflow update logic --- .../fieldcontract/EnsuresNonNullIfHandler.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java b/nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java index 9a4421631c..b4b116c545 100644 --- a/nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java +++ b/nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/EnsuresNonNullIfHandler.java @@ -289,8 +289,12 @@ public NullnessHint onDataflowVisitMethodInvocation( Set 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( @@ -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); } }