{"record":{"id":"5f044d451b480b31","repo":"apache/hadoop","slug":"should-replicate-flag-and-ecpolicyname-are-exclusi","errorCode":null,"errorMessage":"SHOULD_REPLICATE flag and ecPolicyName are exclusive parameters. Set both is not allowed!","messagePattern":"SHOULD_REPLICATE flag and ecPolicyName are exclusive parameters\\. Set both is not allowed!","errorType":"validation","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java","lineNumber":2813,"sourceCode":"          .append(\", blockSize=\").append(blockSize)\n          .append(\", supportedVersions=\")\n          .append(Arrays.toString(supportedVersions))\n          .append(\", ecPolicyName=\").append(ecPolicyName)\n          .append(\", storagePolicy=\").append(storagePolicy);\n      NameNode.stateChangeLog.debug(builder.toString());\n    }\n    if (!DFSUtil.isValidName(src) ||\n        FSDirectory.isExactReservedName(src) ||\n        (FSDirectory.isReservedName(src)\n            && !FSDirectory.isReservedRawName(src)\n            && !FSDirectory.isReservedInodesName(src))) {\n      throw new InvalidPathException(src);\n    }\n\n    boolean shouldReplicate = flag.contains(CreateFlag.SHOULD_REPLICATE);\n    if (shouldReplicate &&\n        (!org.apache.commons.lang3.StringUtils.isEmpty(ecPolicyName))) {\n      throw new HadoopIllegalArgumentException(\"SHOULD_REPLICATE flag and \" +\n          \"ecPolicyName are exclusive parameters. Set both is not allowed!\");\n    }\n\n    INodesInPath iip = null;\n    boolean skipSync = true; // until we do something that might create edits\n    HdfsFileStatus stat = null;\n    BlocksMapUpdateInfo toRemoveBlocks = null;\n\n    checkOperation(OperationCategory.WRITE);\n    final FSPermissionChecker pc = getPermissionChecker();\n    writeLock(RwLockMode.FS);\n    try {\n      checkOperation(OperationCategory.WRITE);\n      checkNameNodeSafeMode(\"Cannot create file\" + src);\n\n      iip = FSDirWriteFileOp.resolvePathForStartFile(\n          dir, pc, src, flag, createParent);\n","sourceCodeStart":2795,"sourceCodeEnd":2831,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java#L2795-L2831","documentation":"A single create call cannot both force replicated layout (CreateFlag.SHOULD_REPLICATE) and name an erasure-coding policy via ecPolicyName — the file layout must come from exactly one source. startFile detects the combination before locking and throws HadoopIllegalArgumentException.","triggerScenarios":"DFSClient.create with a flag set containing CreateFlag.SHOULD_REPLICATE and a non-empty ecPolicyName — e.g., wrapper code that sets SHOULD_REPLICATE whenever replication > 0 while also forwarding an EC policy parameter.","commonSituations":"Migration code that hardcodes the replicate flag for legacy layout and later adds the ecPolicyName parameter; frameworks whose create wrapper fills both fields; copy-paste from an EC example into code that already sets the flag.","solutions":["Drop CreateFlag.SHOULD_REPLICATE from the flag set and keep ecPolicyName (EC layout)","Or pass ecPolicyName null/empty and keep SHOULD_REPLICATE (replicated layout)"],"exampleFix":"// before\nfs.create(path, FsPermission.getDefault(),\n    EnumSet.of(CreateFlag.CREATE, CreateFlag.SHOULD_REPLICATE), 4096, (short) 3, 1 << 20, null, \"RS-6-3-1024k\");\n// after: pick exactly one layout source\nfs.create(path, FsPermission.getDefault(),\n    EnumSet.of(CreateFlag.CREATE), 4096, (short) 3, 1 << 20, null, \"RS-6-3-1024k\");","handlingStrategy":"validation","validationCode":"boolean replicate = flags.contains(CreateFlag.SHOULD_REPLICATE);\nboolean hasEc = ecPolicyName != null && !ecPolicyName.isEmpty();\nif (replicate && hasEc) throw new IllegalArgumentException(\"pick SHOULD_REPLICATE or ecPolicyName, not both\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Encapsulate create() calls in one wrapper that decides the layout exactly once","Assert the flag/policy invariant in unit tests of your FS access layer"],"tags":["hdfs","erasure-coding","create-flags","mutually-exclusive-parameters"],"backgroundTag":"mutually-exclusive-parameters","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}