From 1b1967c089d99fd41e7b0893233265c871599fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Aniche?= Date: Sun, 29 Sep 2024 18:11:08 +0200 Subject: [PATCH] Fix nullaway issues in nullaway --- .../fieldcontract/EnsuresNonNullIfHandler.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 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 ad41f67eef..d26fee8e90 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 @@ -170,7 +170,8 @@ public void onDataflowVisitReturn( // Get the declared configuration of the EnsureNonNullIf method under analysis Symbol.MethodSymbol methodSymbolUnderAnalysis = - methodAnalysisContextUnderAnalysis.methodSymbol(); + NullabilityUtil.castToNonNull(methodAnalysisContextUnderAnalysis).methodSymbol(); + Set fieldNames = getAnnotationValueArray(methodSymbolUnderAnalysis, annotName, false); if (fieldNames == null) { throw new RuntimeException("List of field names shouldn't be null"); @@ -197,8 +198,8 @@ public void onDataflowVisitReturn( } boolean evaluatesToLiteral = expressionAsBoolean.isPresent(); - boolean evaluatesToFalse = evaluatesToLiteral && !expressionAsBoolean.get(); - boolean evaluatesToTrue = evaluatesToLiteral && expressionAsBoolean.get(); + boolean evaluatesToFalse = expressionAsBoolean.isPresent() && !expressionAsBoolean.get(); + boolean evaluatesToTrue = expressionAsBoolean.isPresent() && expressionAsBoolean.get(); /* * Decide whether the semantics of this ReturnTree are correct. @@ -243,7 +244,9 @@ public void onDataflowVisitReturn( } private void raiseError(Tree returnTree, VisitorState state, String message) { - NullAway analysis = methodAnalysisContextUnderAnalysis.analysis(); + NullAway analysis = + NullabilityUtil.castToNonNull(methodAnalysisContextUnderAnalysis).analysis(); + state.reportMatch( analysis .getErrorBuilder()