{"record":{"id":"b4e80664d2e357e8","repo":"apache/hadoop","slug":"buffer-size-must-be-greater-than-0","errorCode":null,"errorMessage":"Buffer size must be greater than 0","messagePattern":"Buffer size must be greater than 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java","lineNumber":103,"sourceCode":"    }\n    \n    public static class ReplicationFactor extends CreateOpts {\n      private final short replication;\n      protected ReplicationFactor(short rf) { \n        if (rf <= 0) {\n          throw new IllegalArgumentException(\n                      \"Replication must be greater than 0\");\n        }\n        replication = rf;\n      }\n      public short getValue() { return replication; }\n    }\n    \n    public static class BufferSize extends CreateOpts {\n      private final int bufferSize;\n      protected BufferSize(int bs) {\n        if (bs <= 0) {\n          throw new IllegalArgumentException(\n                        \"Buffer size must be greater than 0\");\n        }\n        bufferSize = bs; \n      }\n      public int getValue() { return bufferSize; }\n    }\n\n    /** This is not needed if ChecksumParam is specified. **/\n    public static class BytesPerChecksum extends CreateOpts {\n      private final int bytesPerChecksum;\n      protected BytesPerChecksum(short bpc) { \n        if (bpc <= 0) {\n          throw new IllegalArgumentException(\n                        \"Bytes per checksum must be greater than 0\");\n        }\n        bytesPerChecksum = bpc; \n      }\n      public int getValue() { return bytesPerChecksum; }","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java#L85-L121","documentation":"Options.CreateOpts.BufferSize validates that the stream buffer size passed to FileSystem.create(path, CreateOpts.bufferSize(bs), ...) is a positive int; bs <= 0 throws IllegalArgumentException from the constructor.","triggerScenarios":"CreateOpts.bufferSize(n) with n <= 0 — typically io.file.buffer.size misconfigured to 0, a size computation underflowing, or an unvalidated user setting forwarded directly.","commonSituations":"Bad buffer-size config defaults, environment-specific overrides (small containers) set to 0, unit bugs (KB vs bytes miscalculation to zero).","solutions":["Set io.file.buffer.size (or your key) to a positive value, e.g. 4096","Clamp to a sane floor before constructing the option: Math.max(1, n)","Validate all size inputs before building CreateOpts"],"exampleFix":"// before\nCreateOpts.bufferSize(conf.getInt(\"io.file.buffer.size\", 0))\n// after\nint buf = Math.max(1, conf.getInt(\"io.file.buffer.size\", 4096));\nCreateOpts.bufferSize(buf);","handlingStrategy":"validation","validationCode":"int buf = Math.max(1, conf.getInt(\"io.file.buffer.size\", 4096));\nif (buf <= 0) throw new IllegalArgumentException(\"buffer size must be > 0\");\nfs.create(out, CreateOpts.bufferSize(buf));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep io.file.buffer.size positive in config","Clamp computed sizes to a floor of 1","Validate size inputs before constructing CreateOpts"],"tags":["create-options","buffer-size","illegal-argument","validation"],"backgroundTag":"invalid-buffer-size","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}