apache/hadoop · error · NoSuchElementException

No attribute for " + symbol

Error message

No attribute for " + symbol

What it means

DistCpOptions.FileAttribute.getAttribute maps each letter of the -p value to an enum constant by first letter, case-insensitively: r=REPLICATION, b=BLOCKSIZE, u=USER, g=GROUP, p=PERMISSION, c=CHECKSUMTYPE, a=ACL, x=XATTR, t=TIMES, e=ERASURECODINGPOLICY. A letter with no matching constant throws NoSuchElementException('No attribute for <symbol>') while parsing options. An empty -p value is valid and preserves everything.

Source

Thrown at hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCpOptions.java:190

  public enum FileAttribute {
    REPLICATION,    // R
    BLOCKSIZE,      // B
    USER,           // U
    GROUP,          // G
    PERMISSION,     // P
    CHECKSUMTYPE,   // C
    ACL,            // A
    XATTR,          // X
    TIMES,          // T
    ERASURECODINGPOLICY; // E

    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 DistCpOptions(Builder builder) {
    this.sourceFileListing = builder.sourceFileListing;
    this.sourcePaths = builder.sourcePaths;
    this.targetPath = builder.targetPath;

    this.atomicCommit = builder.atomicCommit;
    this.atomicWorkPath = builder.atomicWorkPath;
    this.syncFolder = builder.syncFolder;
    this.deleteMissing = builder.deleteMissing;
    this.ignoreFailures = builder.ignoreFailures;
    this.overwrite = builder.overwrite;
    this.append = builder.append;
    this.skipCRC = builder.skipCRC;
    this.blocking = builder.blocking;

View on GitHub (pinned to 2add963021)

Solutions

  1. Use only valid letters, e.g. -p rb (replication+blocksize) or -p rbugp
  2. For 'preserve everything', pass bare -p with no value (empty means all attributes)
  3. Check the -p argument for stray characters or embedded spaces

Example fix

# before
hadoop distcp -p all hdfs://src hdfs://dst
# -> NoSuchElementException: No attribute for l

# after: bare -p preserves all attributes
hadoop distcp -p hdfs://src hdfs://dst
Defensive patterns

Strategy: validation

Validate before calling

private static final String VALID_ATTRS = "rbugpcaxte";

static boolean isValidPreserveValue(String v) {
  // empty means "preserve all" and is valid
  return v == null || v.isEmpty()
      || v.chars().allMatch(c -> VALID_ATTRS.indexOf(c) >= 0);
}

if (!isValidPreserveValue(pValue)) {
  throw new IllegalArgumentException(
      "invalid -p value '" + pValue + "'; valid letters: " + VALID_ATTRS
      + " (or bare -p for all)");
}

Type guard

static boolean isFileAttributeSymbol(char c) {
  return "rbugpcaxte".indexOf(Character.toLowerCase(c)) >= 0;
}

Prevention

When it happens

Trigger: hadoop distcp -p rq ... ('q' matches nothing); word-style values like -p all ('a' is valid for ACL but 'l' and any remaining letters are not); a stray character or space inside the -p value.

Common situations: Typos in hand-written commands; assuming 'a' means 'all' when it means ACL, or copying rsync-style flags; option strings pasted between tools with different vocabularies.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/36fc2fb60dc76bbb. Report an issue: GitHub.