{"record":{"id":"e5a5f93f1dbda1a3","repo":"apache/beam","slug":"lenientformat-errormessagetemplate-errormessageargs","errorCode":null,"errorMessage":"lenientFormat(errorMessageTemplate, errorMessageArgs)","messagePattern":"lenientFormat\\(errorMessageTemplate, errorMessageArgs\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java","lineNumber":98,"sourceCode":"   * @param errorMessageTemplate a template for the exception message should the check fail. The\n   *     message is formed by replacing each {@code %s} placeholder in the template with an\n   *     argument. These are matched by position - the first {@code %s} gets {@code\n   *     errorMessageArgs[0]}, etc. Unmatched arguments will be appended to the formatted message in\n   *     square braces. Unmatched placeholders will be left as-is.\n   * @param errorMessageArgs the arguments to be substituted into the message template. Arguments\n   *     are converted to strings using {@link String#valueOf(Object)}.\n   * @return the non-null reference that was validated\n   * @throws IllegalArgumentException if {@code reference} is null\n   */\n  @CanIgnoreReturnValue\n  @EnsuresNonNull(\"reference\")\n  @Pure\n  public static <T extends @NonNull Object> T checkArgumentNotNull(\n      @Nullable T reference,\n      @Nullable String errorMessageTemplate,\n      @Nullable Object... errorMessageArgs) {\n    if (reference == null) {\n      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, errorMessageArgs));\n    }\n    return reference;\n  }\n\n  /**\n   * Ensures that an object reference passed as a parameter to the calling method is not null.\n   *\n   * <p>See {@link #checkArgumentNotNull(Object, String, Object...)} for details.\n   */\n  @CanIgnoreReturnValue\n  @EnsuresNonNull(\"#1\")\n  @Pure\n  public static <T extends @NonNull Object> T checkArgumentNotNull(\n      @Nullable T obj, @Nullable String errorMessageTemplate, char p1) {\n    if (obj == null) {\n      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1));\n    }\n    return obj;","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java#L80-L116","documentation":"The varargs overload of checkArgumentNotNull throws IllegalArgumentException with a formatted message (lenientFormat of template and args) when the reference is null, giving detailed context like Guava's %s-style templates.","triggerScenarios":"Passing null to an API validating with checkArgumentNotNull(ref, template, args...). The template uses %s placeholders; args may be empty.","commonSituations":"Nullable configuration or computed values (e.g. resolved file paths, credentials) reaching Beam APIs and failing with the formatted message explaining the expectation.","solutions":["Fix the code so the validated value is non-null (initialize, default, or fail earlier).","Read the formatted message to identify the offending parameter.","Move validation earlier (fail fast at configuration time)."],"exampleFix":"// before\nPreconditions.checkArgumentNotNull(path, \"Path %s not resolved\", id);\n// after\nPreconditions.checkArgumentNotNull(resolve(id), \"Path %s not resolved\", id);","handlingStrategy":"validation","validationCode":"if (ref == null) throw new IllegalArgumentException(String.format(template, args));","typeGuard":"null","tryCatchPattern":"try { apiCall(ref); } catch (IllegalArgumentException e) { LOG.error(\"validation failed: {}\", e.getMessage()); }","preventionTips":["Use %s templates with context (parameter names, values) for debuggability","Sanity-check nullable return values before forwarding to Beam APIs","Centralize required-parameter checks in one config-validation step"],"tags":["java","null-check","arguments"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}