code: private static <T> CharSequence formatOrThrow(T item, int index, Formatter<T> formatter) {
      if (item == null) {
        throw new IllegalArgumentException("list element cannot be null at index " + index);
      }
  
      CharSequence formatted = formatter == null ? item.toString() : formatter.format(item);
  
      if (formatted == null) {
        throw new IllegalArgumentException("formatted list element cannot be null at index " + index);
      }
      if (formatted.length() == 0) {
        throw new IllegalArgumentException(
            "formatted list element cannot be empty at index " + index);
      }
  
      return formatted;
    }
docs: Formats {@code item} by passing it to {@code formatter.format()} if {@code formatter} is
  non-null, else calls {@code item.toString()}. Throws an {@link IllegalArgumentException} if
  {@code item} is null, and an {@link IllegalStateException} if {@code formatter.format()}
  returns null.