{"record":{"id":"e622de753bb5894d","repo":"apache/hadoop","slug":"name-cannot-be-null","errorCode":null,"errorMessage":"{name} cannot be null","messagePattern":"(.+?) cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/util/Check.java","lineNumber":47,"sourceCode":" * <p>\n * Commonly used for method arguments preconditions.\n */\n@InterfaceAudience.Private\npublic class Check {\n\n  /**\n   * Verifies a variable is not NULL.\n   *\n   * @param obj the variable to check.\n   * @param name the name to use in the exception message.\n   *\n   * @return the variable.\n   *\n   * @throws IllegalArgumentException if the variable is NULL.\n   */\n  public static <T> T notNull(T obj, String name) {\n    if (obj == null) {\n      throw new IllegalArgumentException(name + \" cannot be null\");\n    }\n    return obj;\n  }\n\n  /**\n   * Verifies a list does not have any NULL elements.\n   *\n   * @param list the list to check.\n   * @param name the name to use in the exception message.\n   *\n   * @return the list.\n   *\n   * @throws IllegalArgumentException if the list has NULL elements.\n   */\n  public static <T> List<T> notNullElements(List<T> list, String name) {\n    notNull(list, name);\n    for (int i = 0; i < list.size(); i++) {\n      notNull(list.get(i), MessageFormat.format(\"list [{0}] element [{1}]\", name, i));","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/util/Check.java#L29-L65","documentation":"Check.notNull(obj, name) is the httpfs library's argument guard: it throws IllegalArgumentException('<name> cannot be null') when a caller passes null to any API parameter guarded by it (for example the 'user'/'conf' arguments of FileSystemAccess.execute and createFileSystemInternal). This is a programmer/argument error, not an environment problem.","triggerScenarios":"Calling any guarded API with a null argument, e.g. FileSystemAccess.execute(null, conf, executor) or createFileSystem(user, null); Check.notNullable-style guards run before any work starts and fail fast.","commonSituations":"A web layer derives the user from a request and forwards it without checking presence (missing doAs/user.name parameter); null Configuration produced by a broken config loader passed into execute(); unit tests calling the service with placeholder nulls.","solutions":["Look at the exception message - it names the exact argument that was null","Fix the caller to pass a non-null value (e.g. reject requests without a user parameter with a 4xx before reaching the service)","For 'user', validate the incoming proxy/doAs parameter at the HTTP boundary","Add unit tests covering the missing-argument path"],"exampleFix":"// before\nString user = request.getParameter(\"user.name\");\nfsAccess.execute(user, conf, executor); // null user -> IllegalArgumentException\n\n// after\nString user = request.getParameter(\"user.name\");\nif (user == null || user.isEmpty()) { throw new IllegalArgumentException(\"user.name required\"); }\nfsAccess.execute(user, conf, executor);","handlingStrategy":"validation","validationCode":"import java.util.Objects;\n\nString user = Objects.requireNonNullElse(requestedUser, \"\");\nif (user.isEmpty()) { throw new IllegalArgumentException(\"user required\"); }\n// only reach guarded APIs with non-null arguments\nfsAccess.execute(user, Objects.requireNonNull(conf, \"conf\"), executor);","typeGuard":"static boolean isUsableUser(String s) {\n  return s != null && !s.isEmpty();\n}","tryCatchPattern":"try {\n  fsAccess.execute(user, conf, executor);\n} catch (IllegalArgumentException ex) {\n  // message names the null argument, e.g. 'user cannot be null' - caller bug, do not retry\n  throw new BadRequestException(ex.getMessage(), ex);\n}","preventionTips":["Validate arguments at the system boundary (HTTP request parsing) before calling service APIs","Use Objects.requireNonNull with your own message at call sites where null is a bug","Map IllegalArgumentException from Check helpers to 4xx responses - they are client/programmer errors, never retry them"],"tags":["httpfs","null-check","argument-validation","programming-error"],"backgroundTag":"null-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}