public Description createErrorDescription()

in nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java [116:159]


  public Description createErrorDescription(
      ErrorMessage errorMessage,
      @Nullable Tree suggestTree,
      Description.Builder descriptionBuilder,
      VisitorState state,
      @Nullable Symbol nonNullTarget) {
    Description.Builder builder = descriptionBuilder.setMessage(errorMessage.message);
    String checkName = CORE_CHECK_NAME;
    if (errorMessage.messageType.equals(GET_ON_EMPTY_OPTIONAL)) {
      checkName = OPTIONAL_CHECK_NAME;
    } else if (errorMessage.messageType.equals(FIELD_NO_INIT)
        || errorMessage.messageType.equals(METHOD_NO_INIT)
        || errorMessage.messageType.equals(NONNULL_FIELD_READ_BEFORE_INIT)) {
      checkName = INITIALIZATION_CHECK_NAME;
    }

    // Mildly expensive state.getPath() traversal, occurs only once per potentially
    // reported error.
    if (hasPathSuppression(state.getPath(), checkName)) {
      return Description.NO_MATCH;
    }

    if (config.suggestSuppressions() && suggestTree != null) {
      builder = addSuggestedSuppression(errorMessage, suggestTree, builder, state);
    }

    if (config.serializationIsActive()) {
      // For the case of initializer errors, the leaf of state.getPath() may not be the field /
      // method on which the error is being reported (since we do a class-wide analysis to find such
      // errors).  In such cases, the suggestTree is the appropriate field / method tree, so use
      // that as the errorTree for serialization.
      Tree errorTree =
          (suggestTree != null
                  && (errorMessage.messageType.equals(FIELD_NO_INIT)
                      || errorMessage.messageType.equals(METHOD_NO_INIT)))
              ? suggestTree
              : state.getPath().getLeaf();
      SerializationService.serializeReportingError(
          config, state, errorTree, nonNullTarget, errorMessage);
    }

    // #letbuildersbuild
    return builder.build();
  }