apache/beam · error · IllegalArgumentException

lenientFormat(errorMessageTemplate, p1)

Error message

lenientFormat(errorMessageTemplate, p1)

What it means

The single-arg (char p1) overload of checkArgumentNotNull throws IllegalArgumentException with lenientFormat(template, p1) when the object is null. It avoids varargs boxing for the common one-character-argument message case.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java:114

      @Nullable Object... errorMessageArgs) {
    if (reference == null) {
      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, errorMessageArgs));
    }
    return reference;
  }

  /**
   * Ensures that an object reference passed as a parameter to the calling method is not null.
   *
   * <p>See {@link #checkArgumentNotNull(Object, String, Object...)} for details.
   */
  @CanIgnoreReturnValue
  @EnsuresNonNull("#1")
  @Pure
  public static <T extends @NonNull Object> T checkArgumentNotNull(
      @Nullable T obj, @Nullable String errorMessageTemplate, char p1) {
    if (obj == null) {
      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1));
    }
    return obj;
  }

  /**
   * Ensures that an object reference passed as a parameter to the calling method is not null.
   *
   * <p>See {@link #checkArgumentNotNull(Object, String, Object...)} for details.
   */
  @CanIgnoreReturnValue
  @EnsuresNonNull("#1")
  @Pure
  public static <T extends @NonNull Object> T checkArgumentNotNull(
      @Nullable T obj, @Nullable String errorMessageTemplate, int p1) {
    if (obj == null) {
      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1));
    }
    return obj;

View on GitHub (pinned to 12126d8942)

Solutions

  1. Guarantee the argument is non-null before the call.
  2. Use the exception message to locate the null value.
  3. Initialize defaults or fail fast during configuration parsing.

Example fix

// before
Preconditions.checkArgumentNotNull(obj, "Bad shard char %s", c);
// after
Preconditions.checkArgumentNotNull(loadObj(), "Bad shard char %s", c);
Defensive patterns

Strategy: validation

Validate before calling

if (obj == null) throw new IllegalArgumentException(String.format(template, p1));

Type guard

null

Try / catch

try { apiCall(obj); } catch (IllegalArgumentException e) { LOG.error("validation failed: {}", e.getMessage()); }

Prevention

When it happens

Trigger: Passing a null object to an API that validates with checkArgumentNotNull(obj, template, char p1); the thrown message embeds the char argument.

Common situations: Same as other checkArgumentNotNull overloads: null values (often configuration or lookup results) reaching Beam APIs during pipeline setup.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/226122afcaf71def. Report an issue: GitHub.