{"record":{"id":"f936470283fdb48c","repo":"apache/hadoop","slug":"parameter-0-it-s-length-must-be-at-least-1","errorCode":null,"errorMessage":"Parameter [{0}], it's length must be at least 1","messagePattern":"Parameter \\[(.+?)\\], it's length must be at least 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/UserParam.java","lineNumber":58,"sourceCode":"  }\n\n  @VisibleForTesting\n  public static void setUserPatternDomain(Domain dm) {\n    domain = dm;\n  }\n\n  public static void setUserPattern(String pattern) {\n    domain = new Domain(NAME, Pattern.compile(pattern));\n  }\n\n  private static String validateLength(String str) {\n    if (str == null) {\n      throw new IllegalArgumentException(\n        MessageFormat.format(\"Parameter [{0}], cannot be NULL\", NAME));\n    }\n    int len = str.length();\n    if (len < 1) {\n      throw new IllegalArgumentException(MessageFormat.format(\n        \"Parameter [{0}], it's length must be at least 1\", NAME));\n    }\n    return str;\n  }\n\n  /**\n   * Constructor.\n   * @param str a string representation of the parameter value.\n   */\n  public UserParam(final String str) {\n    super(domain, str == null ||\n        str.equals(DEFAULT) ? null : validateLength(str));\n  }\n\n  /**\n   * Construct an object from a UGI.\n   */\n  public UserParam(final UserGroupInformation ugi) {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/UserParam.java#L40-L76","documentation":"The second guard in UserParam.validateLength (UserParam.java:56-60): a non-null username whose length is less than 1 — i.e. the empty string — throws this IllegalArgumentException. As with the null case, only the UserParam(UserGroupInformation) path can produce it, because the String constructor maps \"\" to absent; the message uses MessageFormat with the parameter name 'user.name'. It means the effective short username from the UGI is empty.","triggerScenarios":"ugi.getShortUserName() returning \"\" — a principal like '/host@REALM' or '@REALM' whose primary component is empty; a proxy-user chain resolving to an empty name; test fixtures with UserGroupInformation.createRemoteUser(\"\").","commonSituations":"Host-keytab principals without a primary; SPNEGO configurations that strip the realm and user part; custom auth filters deriving doAs users from headers that arrive empty; CI environments without a login user where the short name degenerates to empty.","solutions":["Validate the short username at startup: if ugi.getShortUserName() is empty, abort with a configuration error instead of calling WebHDFS.","Fix the principal/keytab so it has a real primary component (user@REALM); verify with klist and UserGroupInformation.getLoginUser().getUserName().","For proxied requests, ensure the effective user is never the empty string before building parameters."],"exampleFix":"// before\nparams.add(new UserParam(UserGroupInformation.getCurrentUser()));\n// after\nString name = UserGroupInformation.getCurrentUser().getShortUserName();\nPreconditions.checkState(name != null && !name.isEmpty(), \"empty short username from UGI\");\nparams.add(new UserParam(name));","handlingStrategy":"validation","validationCode":"static String requireNonEmptyShortName(UserGroupInformation ugi) {\n  String n = ugi.getShortUserName();\n  if (n == null || n.isEmpty()) throw new IllegalStateException(\"empty short username from UGI \" + ugi.getUserName());\n  return n;\n}","typeGuard":"static boolean hasNonEmptyShortUserName(UserGroupInformation ugi) {\n  String n = ugi == null ? null : ugi.getShortUserName();\n  return n != null && !n.isEmpty();\n}","tryCatchPattern":null,"preventionTips":["Check short username at authentication time, not per request.","Never construct UserParam from a proxy-user whose effective name may be empty."],"tags":["webhdfs","user-param","authentication","validation","hdfs"],"backgroundTag":"missing-user-parameter","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}