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 117326ebde..e7c2427980 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 @@ -224,11 +224,10 @@ public void onDataflowVisitReturn( */ if (allFieldsAreNonNull) { if (evaluatesToLiteral && evaluatesToFalse) { - String message = - String.format( - "The method ensures the %s of the fields, but doesn't return true", - (trueIfNonNull ? "non-nullability" : "nullability")); - raiseError(returnTree, state, message); + raiseError( + returnTree, + state, + "The method ensures the non-nullability of the fields, but returns incorrectly"); } } else { if (evaluatesToTrue || !evaluatesToLiteral) { diff --git a/nullaway/src/test/java/com/uber/nullaway/EnsuresNonNullIfTests.java b/nullaway/src/test/java/com/uber/nullaway/EnsuresNonNullIfTests.java index 24bb3b8cfa..9936b363a1 100644 --- a/nullaway/src/test/java/com/uber/nullaway/EnsuresNonNullIfTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/EnsuresNonNullIfTests.java @@ -525,7 +525,7 @@ public void semanticIssues_doesntEnsureNonNullabilityOfFields() { " @EnsuresNonNullIf(value=\"nullableItem\", result=true)", " public boolean hasNullableItem() {", " if(nullableItem != null) {", - " // BUG: Diagnostic contains: The method ensures the non-nullability of the fields, but doesn't return true", + " // BUG: Diagnostic contains: The method ensures the non-nullability of the fields, but returns incorrectly", " return false;", " } else {", " // BUG: Diagnostic contains: Method is annotated with @EnsuresNonNullIf but does not ensure fields [nullableItem]", @@ -558,7 +558,7 @@ public void semanticIssues_doesntEnsureNonNullabilityOfFields_resultFalse() { " @EnsuresNonNullIf(value=\"nullableItem\", result=false)", " public boolean doesNotHaveNullableItem() {", " if(nullableItem != null) {", - " // BUG: Diagnostic contains: The method ensures the nullability of the fields, but doesn't return true", + " // BUG: Diagnostic contains: The method ensures the non-nullability of the fields, but returns incorrectly", " return false;", " } else {", " // BUG: Diagnostic contains: Method is annotated with @EnsuresNonNullIf but does not ensure fields [nullableItem]", @@ -681,7 +681,7 @@ public void semanticIssues_methodDeclarationReversed() { " @EnsuresNonNullIf(value=\"nullableItem\", result=true)", " public boolean hasNullableItem() {", " if(nullableItem != null) {", - " // BUG: Diagnostic contains: The method ensures the non-nullability of the fields, but doesn't return true", + " // BUG: Diagnostic contains: The method ensures the non-nullability of the fields, but returns incorrectly", " return false;", " } else {", " // BUG: Diagnostic contains: Method is annotated with @EnsuresNonNullIf but does not ensure fields [nullableItem]",