{"record":{"id":"ee8d960223a0f993","repo":"apache/hadoop","slug":"name-cannot-be-empty","errorCode":null,"errorMessage":"{name} cannot be empty","messagePattern":"(.+?) cannot be empty","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":85,"sourceCode":"    return list;\n  }\n\n  /**\n   * Verifies a string is not NULL and not emtpy\n   *\n   * @param str 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 or empty.\n   */\n  public static String notEmpty(String str, String name) {\n    if (str == null) {\n      throw new IllegalArgumentException(name + \" cannot be null\");\n    }\n    if (str.length() == 0) {\n      throw new IllegalArgumentException(name + \" cannot be empty\");\n    }\n    return str;\n  }\n\n  /**\n   * Verifies a string list is not NULL and not emtpy\n   *\n   * @param list the list to check.\n   * @param name the name to use in the exception message.\n   *\n   * @return the variable.\n   *\n   * @throws IllegalArgumentException if the string list has NULL or empty\n   * elements.\n   */\n  public static List<String> notEmptyElements(List<String> list, String name) {\n    notNull(list, name);\n    for (int i = 0; i < list.size(); i++) {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/util/Check.java#L67-L103","documentation":"Check.notEmpty(str, name) throws IllegalArgumentException('<name> cannot be empty') on its second branch: the string is non-null but has length 0. It guards string parameters of the httpfs service API (e.g. the 'user' argument of FileSystemAccess.execute / createFileSystemInternal), so an empty string is rejected just like null.","triggerScenarios":"Calling a guarded API with \"\", e.g. execute(\"\", conf, executor) or createFileSystem(\"\", conf) - the null branch is skipped because the reference is non-null, then str.length()==0 triggers this throw.","commonSituations":"Frontend sends an empty user/doAs parameter that is trimmed and forwarded; string trimming logic reduces whitespace-only input to \"\" before the call; configuration-derived usernames defaulting to an empty string.","solutions":["The message names the empty parameter - fix the caller to supply a real value","Trim and validate input at the request boundary: reject null, empty, and whitespace-only strings with a 4xx before invoking the service","Log the offending parameter at the boundary so bad requests are diagnosable without stack traces","Add tests for the empty-string input path"],"exampleFix":"// before\nString user = StringUtils.trimToEmpty(req.getParameter(\"doas\")); // '' for absent param\nfsAccess.execute(user, conf, executor); // IllegalArgumentException: user cannot be empty\n\n// after\nString user = StringUtils.trimToNull(req.getParameter(\"doas\"));\nif (user == null) {\n  resp.sendError(HttpServletResponse.SC_BAD_REQUEST, \"doas parameter required\");\n  return;\n}\nfsAccess.execute(user, conf, executor);","handlingStrategy":"validation","validationCode":"import org.apache.commons.lang3.StringUtils;\n\nString user = req.getParameter(\"doas\");\nif (StringUtils.isBlank(user)) {\n  resp.sendError(javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST, \"doas parameter must be non-empty\");\n  return;\n}\nfsAccess.execute(user.trim(), conf, executor);","typeGuard":"static boolean isNonEmptyString(String s) {\n  return s != null && !s.trim().isEmpty();\n}","tryCatchPattern":"try {\n  fsAccess.execute(user, conf, executor);\n} catch (IllegalArgumentException ex) {\n  if (ex.getMessage().endsWith(\"cannot be empty\")) {\n    // empty string argument - client input problem, map to 400 and do not retry\n    resp.sendError(400, ex.getMessage());\n    return;\n  }\n  throw ex;\n}","preventionTips":["Use StringUtils.isBlank/trims at the boundary so null and whitespace-only both become validation failures","Normalize input once (trim) and pass the normalized value downstream","Reject empty identifiers early with a 4xx instead of letting them reach service APIs"],"tags":["httpfs","empty-string","argument-validation","input-validation"],"backgroundTag":"empty-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}