apache/hadoop · error · HadoopIllegalArgumentException
XAttr name cannot be empty.
Error message
XAttr name cannot be empty.
What it means
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.').
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/XAttrHelper.java:57
public static XAttr buildXAttr(String name) {
return buildXAttr(name, null);
}
/**
* Build <code>XAttr</code> from name with prefix and value.
* Name can not be null. Value can be null. The name and prefix
* are validated.
* Both name and namespace are case sensitive.
*/
public static XAttr buildXAttr(String name, byte[] value) {
Preconditions.checkNotNull(name, "XAttr name cannot be null.");
final int prefixIndex = name.indexOf(".");
if (prefixIndex < 3) {// Prefix length is at least 3.
throw new HadoopIllegalArgumentException("An XAttr name must be " +
"prefixed with user/trusted/security/system/raw, followed by a '.'");
} else if (prefixIndex == name.length() - 1) {
throw new HadoopIllegalArgumentException("XAttr name cannot be empty.");
}
NameSpace ns;
final String prefix = name.substring(0, prefixIndex);
if (StringUtils.equalsIgnoreCase(prefix, NameSpace.USER.toString())) {
ns = NameSpace.USER;
} else if (
StringUtils.equalsIgnoreCase(prefix, NameSpace.TRUSTED.toString())) {
ns = NameSpace.TRUSTED;
} else if (
StringUtils.equalsIgnoreCase(prefix, NameSpace.SYSTEM.toString())) {
ns = NameSpace.SYSTEM;
} else if (
StringUtils.equalsIgnoreCase(prefix, NameSpace.SECURITY.toString())) {
ns = NameSpace.SECURITY;
} else if (
StringUtils.equalsIgnoreCase(prefix, NameSpace.RAW.toString())) {
ns = NameSpace.RAW;View on GitHub (pinned to 2add963021)
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.
Example fix
// before String name = "user." + attrSuffix; // attrSuffix == "" dfs.setXAttr(path, name, value); // after Preconditions.checkArgument(!attrSuffix.isEmpty(), "attr suffix required"); dfs.setXAttr(path, "user." + attrSuffix, value);
Defensive patterns
Strategy: validation
Validate before calling
if (name == null || name.isEmpty()
|| name.charAt(name.length() - 1) == '.') {
throw new IllegalArgumentException(
"xattr name must have a non-empty part after '<namespace>.': " + name);
} Try / catch
try {
dfs.setXAttr(path, name, value);
} catch (HadoopIllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("cannot be empty")) {
// empty attribute suffix: fix the caller's input assembly
throw new IllegalArgumentException("Empty xattr suffix in '" + name + "'", e);
}
throw e;
} Prevention
- 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.
When it happens
Trigger: setXAttr/removeXAttr/getXAttrs with a name like 'user.' or 'raw.' — a trailing dot with nothing after it.
Common situations: 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.
Related errors
- An XAttr name must be prefixed with user/trusted/security/sy
- XAttr names can not be null or empty.
- Path part {s} from URI {p} is not a valid filename.
- {} doesn't support setXAttr
- {} doesn't support getXAttr
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/4cfc4605c2582444.
Report an issue: GitHub.