{"record":{"id":"ef87974e0adda0b6","repo":"apache/hadoop","slug":"no-attribute-for","errorCode":null,"errorMessage":"No attribute for {}","messagePattern":"No attribute for (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java","lineNumber":144,"sourceCode":"    if (preserve) {\n      preserve(FileAttribute.TIMESTAMPS);\n      preserve(FileAttribute.OWNERSHIP);\n      preserve(FileAttribute.PERMISSION);\n    } else {\n      preserveStatus.clear();\n    }\n  }\n  \n  protected enum FileAttribute {\n    TIMESTAMPS, OWNERSHIP, PERMISSION, ACL, XATTR;\n\n    public static FileAttribute getAttribute(char symbol) {\n      for (FileAttribute attribute : values()) {\n        if (attribute.name().charAt(0) == Character.toUpperCase(symbol)) {\n          return attribute;\n        }\n      }\n      throw new NoSuchElementException(\"No attribute for \" + symbol);\n    }\n  }\n  \n  private EnumSet<FileAttribute> preserveStatus = \n      EnumSet.noneOf(FileAttribute.class);\n  \n  /**\n   * Checks if the input attribute should be preserved or not\n   *\n   * @param attribute - Attribute to check\n   * @return boolean true if attribute should be preserved, false otherwise\n   */\n  private boolean shouldPreserve(FileAttribute attribute) {\n    return preserveStatus.contains(attribute);\n  }\n  \n  /**\n   * Add file attributes that need to be preserved. This method may be","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java#L126-L162","documentation":"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.","triggerScenarios":"'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.","commonSituations":"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.","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"],"exampleFix":"# before\nhdfs dfs -cp -pz /src /dst\n# after\nhdfs dfs -cp -p /src /dst\n# or preserve only timestamps+permissions:\nhdfs dfs -cp -ptp /src /dst","handlingStrategy":"validation","validationCode":"// validate a -p[attrs] suffix for hdfs dfs -cp before invoking\nstatic boolean isValidPreserveSpec(String s) {\n  for (char c : s.substring(2).toCharArray()) {\n    if (\"ptopaxPTOPAX\".indexOf(c) < 0) return false; // p=permission t=timestamps o=ownership a=ACL x=xattr\n  }\n  return true;\n}\nif (arg.startsWith(\"-p\") && arg.length() > 2 && !isValidPreserveSpec(arg)) {\n  throw new IllegalArgumentException(\"-p accepts only t,o,p,a,x: \" + arg);\n}","typeGuard":"// narrows a char to a valid FileAttribute symbol\nstatic Optional<CommandWithDestination.FileAttribute> asAttribute(char c) {\n  return switch (Character.toUpperCase(c)) {\n    case 'T' -> Optional.of(FileAttribute.TIMESTAMPS);\n    case 'O' -> Optional.of(FileAttribute.OWNERSHIP);\n    case 'P' -> Optional.of(FileAttribute.PERMISSION);\n    case 'A' -> Optional.of(FileAttribute.ACL);\n    case 'X' -> Optional.of(FileAttribute.XATTR);\n    default -> Optional.empty();\n  };\n}","tryCatchPattern":null,"preventionTips":["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]*"],"tags":["hadoop","hdfs","cli","option-value","copy","java"],"backgroundTag":"invalid-option-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}