{"record":{"id":"5020c4b423cd3d9f","repo":"apache/hadoop","slug":"bytesperchecksum-option-is-set-multiple-times","errorCode":null,"errorMessage":"BytesPerChecksum option is set multiple times","messagePattern":"BytesPerChecksum 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":566,"sourceCode":"          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(\n              \"Perms option is set multiple times\");\n        }\n        permission = ((CreateOpts.Perms) iOpt).getValue();\n      } else if (CreateOpts.Progress.class.isInstance(iOpt)) {\n        if (progress != null) {\n          throw new HadoopIllegalArgumentException(","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L548-L584","documentation":"AbstractFileSystem.create permits CreateOpts.BytesPerChecksum at most once; a second occurrence throws HadoopIllegalArgumentException up front. bytesPerChecksum is the divisor used later for the blockSize divisibility check, so a duplicated value would make validation meaningless.","triggerScenarios":"Passing CreateOpts.bytesPerChecksum(...) twice, e.g. a checksum-tuning layer appending its value after the caller already set one.","commonSituations":"Applications optimizing checksum settings merging their option with user options; config keys translated to opts in two places (client default + explicit call); duplicated tuning code after refactoring.","solutions":["Pass CreateOpts.bytesPerChecksum exactly once","Replace any existing occurrence with CreateOpts.setOpt(CreateOpts.bytesPerChecksum(n), opts)","Dedupe the opts array by option class before create()"],"exampleFix":"// before\nfc.create(f, flag, CreateOpts.bytesPerChecksum(512),\n    CreateOpts.bytesPerChecksum(1024));\n\n// after\nfc.create(f, flag, CreateOpts.bytesPerChecksum(1024));","handlingStrategy":"validation","validationCode":"if (CreateOpts.getOpt(CreateOpts.BytesPerChecksum.class, opts) != null) {\n  opts = CreateOpts.setOpt(CreateOpts.bytesPerChecksum(n), opts); // replace, don't append\n} else { /* append */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply checksum tuning in exactly one place","Use CreateOpts.setOpt to replace an existing bytesPerChecksum","Dedupe opts by class in shared create wrappers"],"tags":["hadoop","file-create","options","checksum","varargs"],"backgroundTag":"duplicate-create-option","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}