{"record":{"id":"4d10e1008b7c2162","repo":"apache/hadoop","slug":"buffersize-option-is-set-multiple-times","errorCode":null,"errorMessage":"BufferSize option is set multiple times","messagePattern":"BufferSize 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":554,"sourceCode":"    int bufferSize = -1;\n    short replication = -1;\n    long blockSize = -1;\n    int bytesPerChecksum = -1;\n    ChecksumOpt checksumOpt = null;\n    FsPermission permission = null;\n    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(","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L536-L572","documentation":"AbstractFileSystem.create accepts CreateOpts.BufferSize at most once; a second occurrence in the varargs throws HadoopIllegalArgumentException immediately. This is pure argument validation, raised before the create reaches the underlying file system.","triggerScenarios":"Passing CreateOpts.bufferSize(...) twice in a single create() call, e.g. a framework defaulting the buffer size being appended after the caller's own buffer size option.","commonSituations":"Option-merging code that concatenates default opts with user opts; copy-pasted option lists where a buffer size was already present; config-driven option assembly applied twice.","solutions":["Pass CreateOpts.bufferSize exactly once — inspect the existing varargs before appending","Replace instead of append with CreateOpts.setOpt(CreateOpts.bufferSize(n), opts)","Dedupe opts by option class before create()"],"exampleFix":"// before\nfc.create(f, flag, CreateOpts.bufferSize(4096), CreateOpts.bufferSize(8192));\n\n// after\nfc.create(f, flag, CreateOpts.bufferSize(8192));","handlingStrategy":"validation","validationCode":"if (Collections.frequency(Arrays.asList(opts).stream().map(o -> o.getClass()).collect(toList()), Options.CreateOpts.BufferSize.class) > 1) throw new IllegalArgumentException(\"bufferSize duplicated\");\n// or simply: opts = CreateOpts.setOpt(CreateOpts.bufferSize(n), opts);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass each create option exactly once from a single layer of code","Use CreateOpts.setOpt for overrides","Dedupe opts by class in shared create wrappers"],"tags":["hadoop","file-create","options","varargs","validation"],"backgroundTag":"duplicate-create-option","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}