{"record":{"id":"6cafa1ce5de60f3d","repo":"apache/hadoop","slug":"xattr-xattrname-does-not-exist-the-create-flag","errorCode":null,"errorMessage":"XAttr: {xAttrName} does not exist. The CREATE flag must be specified.","messagePattern":"XAttr: (.+?) does not exist\\. The CREATE flag must be specified\\.","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/XAttrSetFlag.java","lineNumber":66,"sourceCode":"\n  short getFlag() {\n    return flag;\n  }\n\n  public static void validate(String xAttrName, boolean xAttrExists,\n      EnumSet<XAttrSetFlag> flag) throws IOException {\n    if (flag == null || flag.isEmpty()) {\n      throw new HadoopIllegalArgumentException(\"A flag must be specified.\");\n    }\n\n    if (xAttrExists) {\n      if (!flag.contains(REPLACE)) {\n        throw new IOException(\"XAttr: \" + xAttrName +\n            \" already exists. The REPLACE flag must be specified.\");\n      }\n    } else {\n      if (!flag.contains(CREATE)) {\n        throw new IOException(\"XAttr: \" + xAttrName +\n            \" does not exist. The CREATE flag must be specified.\");\n      }\n    }\n  }\n}\n","sourceCodeStart":48,"sourceCodeEnd":72,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/XAttrSetFlag.java#L48-L72","documentation":"Mirror of the already-exists case in XAttrSetFlag.validate: the attribute does not exist, but the flag set lacks CREATE, so creating it is not authorized. REPLACE-only asserts the attribute exists and will never create it.","triggerScenarios":"setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.REPLACE)) when the attribute was never set, was removed by another client, or the name string does not match the existing attribute exactly.","commonSituations":"Code assuming an earlier init step created the attribute (ordering bug or race with removeXAttr); attribute name typo or wrong namespace prefix; cleanup scripts removing attributes between runs.","solutions":["Use EnumSet.of(CREATE, REPLACE) for upsert behavior","Verify the attribute name matches exactly (namespaces user./trusted./security./raw. are case-sensitive and permission-gated)","If the attribute must pre-exist, create it in a dedicated init step and fail fast when getXAttr returns null"],"exampleFix":"// before\nfs.setXAttr(path, \"user.tag\", value, EnumSet.of(XAttrSetFlag.REPLACE));\n// IOException: XAttr user.tag does not exist...\n\n// after\nfs.setXAttr(path, \"user.tag\", value,\n    EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE));","handlingStrategy":"fallback","validationCode":"byte[] existing = fs.getXAttr(path, name);\nif (existing == null) {\n  fs.setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.CREATE));\n} else {\n  fs.setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.REPLACE));\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.REPLACE));\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"does not exist\")) {\n    fs.setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.CREATE));\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use CREATE|REPLACE for upserts instead of REPLACE alone","Verify exact attribute names (namespace prefix and case) before asserting existence"],"tags":["xattr","extended-attributes","not-found"],"backgroundTag":"attribute-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}