{"record":{"id":"b14d07d850b64085","repo":"apache/hadoop","slug":"an-xattr-name-must-be-prefixed-with-user-trusted-s","errorCode":null,"errorMessage":"An XAttr name must be prefixed with user/trusted/security/system/raw, followed by a '.'","messagePattern":"An XAttr name must be prefixed with user/trusted/security/system/raw, followed by a '\\.'","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":54,"sourceCode":"  /**\n   * Build <code>XAttr</code> from xattr name with prefix.\n   */\n  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;","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/XAttrHelper.java#L36-L72","documentation":"XAttrHelper.buildXAttr(String, byte[]) splits a fully-qualified extended-attribute name into a namespace (the substring before the first '.') and the attribute name (the rest). Every legal namespace — user, trusted, security, system, raw — is at least three characters, so if the first '.' is missing (indexOf == -1) or appears before index 3, no valid namespace can exist and the name is rejected client-side with HadoopIllegalArgumentException before any RPC.","triggerScenarios":"setXAttr(path, name, value) or removeXAttr(path, name) with a name that omits the namespace prefix ('color'), contains no dot at all ('color123'), or has a prefix shorter than three characters ('us.x').","commonSituations":"Applications ported from POSIX xattr APIs where names are unprefixed; tools that assume HDFS applies a default 'user.' namespace (it does not); typos in 'hdfs dfs -setfattr' commands; names built by string concatenation that drops the prefix.","solutions":["Prefix the attribute with a supported namespace, e.g. 'user.color' for ordinary client access.","Use trusted./security./system./raw. only from privileged callers — they are restricted namespaces.","Validate xattr names once (regex '(?i)(user|trusted|security|system|raw)\\..+') at your API boundary."],"exampleFix":"// before\ndfs.setXAttr(path, \"color\", Bytes.toBytes(\"blue\")); // no namespace prefix\n\n// after\ndfs.setXAttr(path, \"user.color\", Bytes.toBytes(\"blue\"));","handlingStrategy":"validation","validationCode":"private static final Pattern VALID_XATTR_NAME =\n    Pattern.compile(\"(?i)(user|trusted|security|system|raw)\\\\..+\");\n\nif (name == null || !VALID_XATTR_NAME.matcher(name).matches()) {\n  throw new IllegalArgumentException(\n      \"xattr name must be '<namespace>.<name>' with namespace in \"\n      + \"user/trusted/security/system/raw, got: \" + name);\n}","typeGuard":null,"tryCatchPattern":"try {\n  dfs.setXAttr(path, name, value);\n} catch (HadoopIllegalArgumentException e) {\n  // invalid name format: surface the offending input for the caller to fix\n  throw new IllegalArgumentException(\n      \"Bad xattr name '\" + name + \"': \" + e.getMessage(), e);\n}","preventionTips":["Store xattr names in constants that include the namespace prefix.","Wrap user-supplied attribute names with 'user.' by default at your API boundary.","Reject unprefixed names early with a clear message instead of letting HDFS throw mid-operation."],"tags":["hdfs","xattr","validation","client-side"],"backgroundTag":"xattr-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}