apache/hadoop · error · NoSuchElementException
No attribute for {}
Error message
No attribute for {} What it means
FileAttribute.getAttribute(char) in CommandWithDestination maps each character of the -p value of 'hdfs dfs -cp' to a preserve-attribute enum. Valid characters are the (case-insensitive) first letters of the enum: t=TIMESTAMPS, o=OWNERSHIP, p=PERMISSION, a=ACL, x=XATTR. Any other character throws NoSuchElementException('No attribute for c') from CopyCommands.Cp.popPreserveOption (CopyCommands.java:204), which crashes option processing with a raw runtime exception.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java:144
if (preserve) {
preserve(FileAttribute.TIMESTAMPS);
preserve(FileAttribute.OWNERSHIP);
preserve(FileAttribute.PERMISSION);
} else {
preserveStatus.clear();
}
}
protected enum FileAttribute {
TIMESTAMPS, OWNERSHIP, PERMISSION, ACL, XATTR;
public static FileAttribute getAttribute(char symbol) {
for (FileAttribute attribute : values()) {
if (attribute.name().charAt(0) == Character.toUpperCase(symbol)) {
return attribute;
}
}
throw new NoSuchElementException("No attribute for " + symbol);
}
}
private EnumSet<FileAttribute> preserveStatus =
EnumSet.noneOf(FileAttribute.class);
/**
* Checks if the input attribute should be preserved or not
*
* @param attribute - Attribute to check
* @return boolean true if attribute should be preserved, false otherwise
*/
private boolean shouldPreserve(FileAttribute attribute) {
return preserveStatus.contains(attribute);
}
/**
* Add file attributes that need to be preserved. This method may beView on GitHub (pinned to 2add963021)
Solutions
- Use only the letters t, o, p, a, x after -p (e.g. 'hdfs dfs -cp -ptop /src /dst')
- Use plain '-p' with no suffix, which preserves all supported attributes
- Remove any '=', commas, or words from the preserve specification - only a bare letter run is accepted
Example fix
# before hdfs dfs -cp -pz /src /dst # after hdfs dfs -cp -p /src /dst # or preserve only timestamps+permissions: hdfs dfs -cp -ptp /src /dst
Defensive patterns
Strategy: validation
Validate before calling
// validate a -p[attrs] suffix for hdfs dfs -cp before invoking
static boolean isValidPreserveSpec(String s) {
for (char c : s.substring(2).toCharArray()) {
if ("ptopaxPTOPAX".indexOf(c) < 0) return false; // p=permission t=timestamps o=ownership a=ACL x=xattr
}
return true;
}
if (arg.startsWith("-p") && arg.length() > 2 && !isValidPreserveSpec(arg)) {
throw new IllegalArgumentException("-p accepts only t,o,p,a,x: " + arg);
} Type guard
// narrows a char to a valid FileAttribute symbol
static Optional<CommandWithDestination.FileAttribute> asAttribute(char c) {
return switch (Character.toUpperCase(c)) {
case 'T' -> Optional.of(FileAttribute.TIMESTAMPS);
case 'O' -> Optional.of(FileAttribute.OWNERSHIP);
case 'P' -> Optional.of(FileAttribute.PERMISSION);
case 'A' -> Optional.of(FileAttribute.ACL);
case 'X' -> Optional.of(FileAttribute.XATTR);
default -> Optional.empty();
};
} Prevention
- Treat -p as a whole-flag by default; add letters only when a specific subset is required
- Do not port GNU cp --preserve words (mode, links, timestamps) into the -p suffix
- Add a lint step for cp commands in shared scripts that regex-checks -p[ptopaxPTOPAX]*
When it happens
Trigger: 'hdfs dfs -cp -pz /src /dst' (no 'z' attribute), '-pm' or '--preserve=mode'-style GNU vocabulary pasted after -p, or a typo like '-pacl' where only single attribute letters are accepted.
Common situations: Users familiar with GNU cp's '--preserve=mode,links' syntax assuming the same words work after -p; uppercase/lowercase confusion is NOT a problem (matching is case-insensitive) but extra letters are; scripting after reading docs for a different Hadoop version.
Related errors
- Illegal option {}
- Not enough arguments: expected {} but got {}
- Too many arguments: expected {} but got {}
- unexpected URISyntaxException
- No such file or directory
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/ef87974e0adda0b6.
Report an issue: GitHub.