{"record":{"id":"566ee27147cac799","repo":"apache/hadoop","slug":"replicationfactor-option-is-set-multiple-times","errorCode":null,"errorMessage":"ReplicationFactor option is set multiple times","messagePattern":"ReplicationFactor option is set multiple times","errorType":"validation","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":560,"sourceCode":"    Progressable progress = null;\n    Boolean createParent = null;\n \n    for (CreateOpts iOpt : opts) {\n      if (CreateOpts.BlockSize.class.isInstance(iOpt)) {\n        if (blockSize != -1) {\n          throw new HadoopIllegalArgumentException(\n              \"BlockSize option is set multiple times\");\n        }\n        blockSize = ((CreateOpts.BlockSize) iOpt).getValue();\n      } else if (CreateOpts.BufferSize.class.isInstance(iOpt)) {\n        if (bufferSize != -1) {\n          throw new HadoopIllegalArgumentException(\n              \"BufferSize option is set multiple times\");\n        }\n        bufferSize = ((CreateOpts.BufferSize) iOpt).getValue();\n      } else if (CreateOpts.ReplicationFactor.class.isInstance(iOpt)) {\n        if (replication != -1) {\n          throw new HadoopIllegalArgumentException(\n              \"ReplicationFactor option is set multiple times\");\n        }\n        replication = ((CreateOpts.ReplicationFactor) iOpt).getValue();\n      } else if (CreateOpts.BytesPerChecksum.class.isInstance(iOpt)) {\n        if (bytesPerChecksum != -1) {\n          throw new HadoopIllegalArgumentException(\n              \"BytesPerChecksum option is set multiple times\");\n        }\n        bytesPerChecksum = ((CreateOpts.BytesPerChecksum) iOpt).getValue();\n      } else if (CreateOpts.ChecksumParam.class.isInstance(iOpt)) {\n        if (checksumOpt != null) {\n          throw new  HadoopIllegalArgumentException(\n              \"CreateChecksumType option is set multiple times\");\n        }\n        checksumOpt = ((CreateOpts.ChecksumParam) iOpt).getValue();\n      } else if (CreateOpts.Perms.class.isInstance(iOpt)) {\n        if (permission != null) {\n          throw new HadoopIllegalArgumentException(","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L542-L578","documentation":"AbstractFileSystem.create allows CreateOpts.ReplicationFactor at most once; a second instance in the varargs throws HadoopIllegalArgumentException during argument processing. The check exists so the effective replication value is never ambiguous.","triggerScenarios":"Two CreateOpts.replication(...) entries in one create() call — commonly a caller-supplied replication plus a library-injected default, or code merging per-job config opts with per-call opts by concatenation.","commonSituations":"Write helpers that enforce a default replication; pipelines that layer options (caller -> service -> client shim) where each layer appends instead of replacing; duplicated code paths both adding the option.","solutions":["Ensure replication is passed once; delete the redundant CreateOpts.replication(...) from one of the layers","Use CreateOpts.setOpt(CreateOpts.replication(r), opts) to replace any existing value","Add a dedupe-by-class step in shared create wrappers"],"exampleFix":"// before\nfc.create(f, flag, CreateOpts.replication((short) 3),\n    CreateOpts.replication((short) 2));\n\n// after\nfc.create(f, flag, CreateOpts.replication((short) 3));","handlingStrategy":"validation","validationCode":"opts = CreateOpts.setOpt(CreateOpts.replication(r), opts); // replaces any existing replication option","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let one component own replication (the caller) and have libraries only replace via setOpt","Check for an existing option with CreateOpts.getOpt(ReplicationFactor.class, opts) before adding","Dedupe opts by class in shared create wrappers"],"tags":["hadoop","file-create","options","varargs","replication"],"backgroundTag":"duplicate-create-option","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}