{"record":{"id":"bad1560044f7a629","repo":"apache/hadoop","slug":"xattr-names-can-not-be-null-or-empty","errorCode":null,"errorMessage":"XAttr names can not be null or empty.","messagePattern":"XAttr names can not be null or 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":163,"sourceCode":"   */\n  public static String getPrefixedName(XAttr xAttr) {\n    if (xAttr == null) {\n      return null;\n    }\n\n    return getPrefixedName(xAttr.getNameSpace(), xAttr.getName());\n  }\n\n  public static String getPrefixedName(XAttr.NameSpace ns, String name) {\n    return StringUtils.toLowerCase(ns.toString()) + \".\" + name;\n  }\n\n  /**\n   * Build <code>XAttr</code> list from xattr name list.\n   */\n  public static List<XAttr> buildXAttrs(List<String> names) {\n    if (names == null || names.isEmpty()) {\n      throw new HadoopIllegalArgumentException(\"XAttr names can not be \" +\n          \"null or empty.\");\n    }\n\n    List<XAttr> xAttrs = Lists.newArrayListWithCapacity(names.size());\n    for (String name : names) {\n      xAttrs.add(buildXAttr(name, null));\n    }\n    return xAttrs;\n  }\n}\n","sourceCodeStart":145,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/XAttrHelper.java#L145-L174","documentation":"XAttrHelper.buildXAttrs(List<String>) converts a caller's list of prefixed xattr names into XAttr objects for the names-filtered xattr read (getXAttrs(path, names)). A null or empty list is rejected immediately with HadoopIllegalArgumentException, because HDFS requires at least one concrete attribute name for that RPC.","triggerScenarios":"dfs.getXAttrs(path, names) where names is null or Collections.emptyList(); also direct calls to XdfsHelper.buildXAttrs with an empty collection. getXAttrs(path) without a list is a different RPC and is fine.","commonSituations":"Wrapper APIs that forward a user-supplied filter list unchecked; code that builds the name list dynamically and passes it through empty; refactors that turn a fixed list into a computed one that can be empty.","solutions":["To read all xattrs, call dfs.getXAttrs(path) with no name list.","Otherwise pass at least one valid prefixed name such as 'user.color'.","Guard wrapper methods: translate null/empty filter lists into the get-all form."],"exampleFix":"// before\nList<String> names = request.getAttrs(); // may be empty\ndfs.getXAttrs(path, names); // throws\n\n// after\nMap<String, byte[]> xattrs = (names == null || names.isEmpty())\n    ? dfs.getXAttrs(path)\n    : dfs.getXAttrs(path, names);","handlingStrategy":"validation","validationCode":"if (names == null || names.isEmpty()) {\n  // names-filtered RPC requires >= 1 name; use the get-all form instead\n  xattrs = dfs.getXAttrs(path);\n} else {\n  xattrs = dfs.getXAttrs(path, names);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat an empty xattr filter list as 'fetch all' at your API boundary.","Never forward unchecked user-supplied name lists to getXAttrs(path, names).","Prefer the no-list getXAttrs(path) when the caller wants everything."],"tags":["hdfs","xattr","validation","empty-collection"],"backgroundTag":"xattr-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}