{"record":{"id":"5584d8a2aff96f87","repo":"apache/beam","slug":"illegalargumentexception","errorCode":null,"errorMessage":"IllegalArgumentException","messagePattern":"IllegalArgumentException","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java","lineNumber":51,"sourceCode":" */\n@Internal\n@SuppressWarnings({\n  \"nullness\" // TODO(https://github.com/apache/beam/issues/20497)\n})\npublic class Preconditions {\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   * @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(@Nullable T reference) {\n    if (reference == null) {\n      throw new IllegalArgumentException();\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 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) {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java#L33-L69","documentation":"Beam's own Preconditions.checkArgumentNotNull throws IllegalArgumentException when the given reference is null, providing a null-check helper with a return value for inline assignment. It mirrors Guava's checkNotNull but signals an argument problem rather than a value problem.","triggerScenarios":"Passing null as an argument to any API that validates it with Preconditions.checkArgumentNotNull, e.g. constructor or method parameters that must be non-null.","commonSituations":"Optional/missing configuration passed into transforms or resources; nullable method returns fed straight into Beam APIs.","solutions":["Ensure the argument is non-null before calling the API.","Add an explicit null check or default value at the call site.","Use the overload with an error message to get a more diagnosable failure."],"exampleFix":"// before\nsink.writeToFile(null);\n// after\ncheckState(path != null, \"output path must be set\");\nsink.writeToFile(path);","handlingStrategy":"validation","validationCode":"if (value == null) { throw new IllegalArgumentException(\"value must not be null\"); }","typeGuard":"null","tryCatchPattern":"try { apiCall(value); } catch (IllegalArgumentException e) { /* null argument rejected */ }","preventionTips":["Validate all inputs at pipeline-construction time","Use Optional and orElse defaults for nullable config","Prefer the checkArgumentNotNull overloads with messages"],"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"}