{"record":{"id":"1e6f4d9153996a13","repo":"apache/beam","slug":"string-valueof-errormessage","errorCode":null,"errorMessage":"String.valueOf(errorMessage)","messagePattern":"String\\.valueOf\\(errorMessage\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java","lineNumber":71,"sourceCode":"    return reference;\n  }\n\n  /**\n   * Ensures that an object reference passed as a parameter to the calling method is not null.\n   *\n   * @param reference an object reference\n   * @param errorMessage the exception message to use if the check fails; will be converted to a\n   *     string 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(\"#1\")\n  @Pure\n  public static <T extends @NonNull Object> T checkArgumentNotNull(\n      @Nullable T reference, @Nullable Object errorMessage) {\n    if (reference == null) {\n      throw new IllegalArgumentException(String.valueOf(errorMessage));\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   * @param reference an object reference\n   * @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   */","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java#L53-L89","documentation":"The two-argument overload of checkArgumentNotNull throws IllegalArgumentException with a caller-supplied message (String.valueOf(errorMessage)) when the reference is null. It exists so failures carry context about which value was unexpectedly null.","triggerScenarios":"Passing null to an API that validates with checkArgumentNotNull(ref, errorMessage); the message parameter itself may be null (then the exception message is \"null\").","commonSituations":"Missing configuration values (null connection strings, null bucket names) reaching Beam APIs during pipeline construction.","solutions":["Supply the required non-null value before the call.","Read the exception message to identify which parameter was null.","Prefer the template/message overloads for better diagnostics."],"exampleFix":"// before\nPreconditions.checkArgumentNotNull(name); // message lost\n// after\nPreconditions.checkNotNull(name, \"name must not be null\");","handlingStrategy":"validation","validationCode":"if (ref == null) throw new IllegalArgumentException(\"meaningful message here\");","typeGuard":"null","tryCatchPattern":"try { apiCall(ref); } catch (IllegalArgumentException e) { LOG.error(\"null arg: {}\", e.getMessage()); }","preventionTips":["Pass a descriptive errorMessage so failures are diagnosable","Fail fast during config parsing instead of deep in the API","Run a dry validation of required parameters before pipeline submission"],"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"}