{"record":{"id":"4cfc4605c2582444","repo":"apache/hadoop","slug":"xattr-name-cannot-be-empty","errorCode":null,"errorMessage":"XAttr name cannot be empty.","messagePattern":"XAttr name cannot be empty\\.","errorType":"validation","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/XAttrHelper.java","lineNumber":57,"sourceCode":"  public static XAttr buildXAttr(String name) {\n    return buildXAttr(name, null);\n  }\n\n  /**\n   * Build <code>XAttr</code> from name with prefix and value.\n   * Name can not be null. Value can be null. The name and prefix\n   * are validated.\n   * Both name and namespace are case sensitive.\n   */\n  public static XAttr buildXAttr(String name, byte[] value) {\n    Preconditions.checkNotNull(name, \"XAttr name cannot be null.\");\n\n    final int prefixIndex = name.indexOf(\".\");\n    if (prefixIndex < 3) {// Prefix length is at least 3.\n      throw new HadoopIllegalArgumentException(\"An XAttr name must be \" +\n          \"prefixed with user/trusted/security/system/raw, followed by a '.'\");\n    } else if (prefixIndex == name.length() - 1) {\n      throw new HadoopIllegalArgumentException(\"XAttr name cannot be empty.\");\n    }\n\n    NameSpace ns;\n    final String prefix = name.substring(0, prefixIndex);\n    if (StringUtils.equalsIgnoreCase(prefix, NameSpace.USER.toString())) {\n      ns = NameSpace.USER;\n    } else if (\n        StringUtils.equalsIgnoreCase(prefix, NameSpace.TRUSTED.toString())) {\n      ns = NameSpace.TRUSTED;\n    } else if (\n        StringUtils.equalsIgnoreCase(prefix, NameSpace.SYSTEM.toString())) {\n      ns = NameSpace.SYSTEM;\n    } else if (\n        StringUtils.equalsIgnoreCase(prefix, NameSpace.SECURITY.toString())) {\n      ns = NameSpace.SECURITY;\n    } else if (\n        StringUtils.equalsIgnoreCase(prefix, NameSpace.RAW.toString())) {\n      ns = NameSpace.RAW;","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/XAttrHelper.java#L39-L75","documentation":"buildXAttr rejects names whose namespace prefix parses but whose attribute part is empty: when the first '.' is the last character of the string (prefixIndex == name.length() - 1), the remainder after the dot is the empty string, so the call fails fast with HadoopIllegalArgumentException ('XAttr name cannot be empty.').","triggerScenarios":"setXAttr/removeXAttr/getXAttrs with a name like 'user.' or 'raw.' — a trailing dot with nothing after it.","commonSituations":"String concatenation where the suffix variable is empty ('user.' + attr with attr == \"\"); templating that renders a bare namespace; input trimmed so it ends at the dot; dynamic name lists containing one malformed entry.","solutions":["Supply a non-empty attribute name after the namespace dot, e.g. 'user.color'.","Check suffix variables for null/empty before assembling the name.","Validate with a regex that requires at least one character after the dot."],"exampleFix":"// before\nString name = \"user.\" + attrSuffix; // attrSuffix == \"\"\ndfs.setXAttr(path, name, value);\n\n// after\nPreconditions.checkArgument(!attrSuffix.isEmpty(), \"attr suffix required\");\ndfs.setXAttr(path, \"user.\" + attrSuffix, value);","handlingStrategy":"validation","validationCode":"if (name == null || name.isEmpty()\n    || name.charAt(name.length() - 1) == '.') {\n  throw new IllegalArgumentException(\n      \"xattr name must have a non-empty part after '<namespace>.': \" + name);\n}","typeGuard":null,"tryCatchPattern":"try {\n  dfs.setXAttr(path, name, value);\n} catch (HadoopIllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"cannot be empty\")) {\n    // empty attribute suffix: fix the caller's input assembly\n    throw new IllegalArgumentException(\"Empty xattr suffix in '\" + name + \"'\", e);\n  }\n  throw e;\n}","preventionTips":["Check suffix variables for null/empty before concatenating 'user.' + suffix.","Validate names with a regex that requires at least one character after the dot.","Unit-test name-building code paths that can pass empty suffixes."],"tags":["hdfs","xattr","validation","empty-value"],"backgroundTag":"xattr-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}