{"record":{"id":"3f6d8fbcaa922e6d","repo":"apache/beam","slug":"lenientformat-errormessagetemplate-p1-p2","errorCode":null,"errorMessage":"lenientFormat(errorMessageTemplate, p1, p2)","messagePattern":"lenientFormat\\(errorMessageTemplate, p1, p2\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java","lineNumber":178,"sourceCode":"      @Nullable T obj, @Nullable String errorMessageTemplate, @Nullable Object p1) {\n    if (obj == null) {\n      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1));\n    }\n    return obj;\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, char p2) {\n    if (obj == null) {\n      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));\n    }\n    return obj;\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, int p2) {\n    if (obj == null) {\n      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2));\n    }\n    return obj;","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java#L160-L196","documentation":"Apache Beam's Preconditions.checkArgumentNotNull(T, String, char, char) throws IllegalArgumentException when the checked reference is null, formatting the message template with two char substitutions via lenientFormat (Preconditions.java:178). It exists to fail fast on violated non-null contracts with descriptive messages.","triggerScenarios":"Calling checkArgumentNotNull(obj, template, c1, c2) where obj is null.","commonSituations":"Passing an unset reference into a Beam API that validates non-nullity while supplying two chars (e.g. delimiters, column names) in the error template.","solutions":["Initialize the flagged reference before the call.","Add an explicit null check with a descriptive message at the call site.","Use the formatted message (contains the two char substitutions) to locate the failing value.","Rework the caller to tolerate null if that is a valid state."],"exampleFix":"// before\nString sep = Preconditions.checkArgumentNotNull(cfg.getSeparator(), \"bad seps %c%c\", a, b);\n// after\ncheckState(cfg.getSeparator() != null, \"separator missing (tried %c and %c)\", a, b);\nString sep = cfg.getSeparator();","handlingStrategy":"validation","validationCode":"if (cfg.getSeparator() == null) {\n  throw new IllegalArgumentException(\"separator must be configured\");\n}","typeGuard":"static <T> boolean nonNull(T v) { return v != null; }","tryCatchPattern":"try {\n  return Preconditions.checkArgumentNotNull(v, \"msg %c%c\", a, b);\n} catch (IllegalArgumentException e) {\n  log.error(\"null argument: {}\", e.getMessage());\n  throw e;\n}","preventionTips":["Set default values for char-delimiter style config fields.","Validate all dependent config in one startup pass.","Wrap third-party lookups so they never return bare null."],"tags":["java","apache-beam","null-check","illegal-argument"],"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"}