in nullaway/src/main/java/com/uber/nullaway/handlers/contract/fieldcontract/RequiresNonNullHandler.java [131:171]
public void onMatchMethodInvocation(
NullAway analysis,
MethodInvocationTree tree,
VisitorState state,
Symbol.MethodSymbol methodSymbol) {
Set<String> fieldNames = getAnnotationValueArray(methodSymbol, annotName, false);
if (fieldNames == null) {
super.onMatchMethodInvocation(analysis, tree, state, methodSymbol);
return;
}
fieldNames = ContractUtils.trimReceivers(fieldNames);
for (String fieldName : fieldNames) {
Symbol.ClassSymbol classSymbol = ASTHelpers.enclosingClass(methodSymbol);
Preconditions.checkNotNull(
classSymbol, "Could not find the enclosing class for method symbol: " + methodSymbol);
VariableElement field = getInstanceFieldOfClass(classSymbol, fieldName);
if (field == null) {
// we will report an error on the method declaration
continue;
}
ExpressionTree methodSelectTree = tree.getMethodSelect();
Nullness nullness =
analysis
.getNullnessAnalysis(state)
.getNullnessOfFieldForReceiverTree(
state.getPath(), state.context, methodSelectTree, field, true);
if (NullabilityUtil.nullnessToBool(nullness)) {
String message = "Expected field " + fieldName + " to be non-null at call site";
state.reportMatch(
analysis
.getErrorBuilder()
.createErrorDescription(
new ErrorMessage(ErrorMessage.MessageTypes.PRECONDITION_NOT_SATISFIED, message),
tree,
analysis.buildDescription(tree),
state,
null));
}
}
}