{"record":{"id":"baa35a2fbe6c1f00","repo":"apache/hadoop","slug":"block-size-must-be-greater-than-0","errorCode":null,"errorMessage":"Block size must be greater than 0","messagePattern":"Block 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":79,"sourceCode":"    }\n    public static Progress progress(Progressable prog) {\n      return new Progress(prog);\n    }\n    public static Perms perms(FsPermission perm) {\n      return new Perms(perm);\n    }\n    public static CreateParent createParent() {\n      return new CreateParent(true);\n    }\n    public static CreateParent donotCreateParent() {\n      return new CreateParent(false);\n    }\n    \n    public static class BlockSize extends CreateOpts {\n      private final long blockSize;\n      protected BlockSize(long bs) {\n        if (bs <= 0) {\n          throw new IllegalArgumentException(\n                        \"Block size must be greater than 0\");\n        }\n        blockSize = bs; \n      }\n      public long getValue() { return blockSize; }\n    }\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    }","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java#L61-L97","documentation":"Options.CreateOpts.BlockSize (used via FileSystem.create(path, CreateOpts.blockSize(bs), ...) and friends) validates in its constructor that the block size is positive; bs <= 0 throws IllegalArgumentException immediately at option construction, before any filesystem call.","triggerScenarios":"CreateOpts.blockSize(n)/new CreateOpts.BlockSize(n) with n <= 0 — commonly a config lookup that defaulted to 0, a -1 'unspecified' sentinel leaking into the opts API, or an arithmetic/unit bug producing zero or negative sizes.","commonSituations":"Missing block-size config keys (fs.local.block.size / dfs.block.size) defaulting wrongly to 0, int overflow when computing sizes, code paths forwarding user input unvalidated.","solutions":["Fix the config source so the resolved block size is positive (check the actual key and its default)","Validate/compute bs > 0 before calling create; use the FileSystem default when unspecified","Never pass -1 sentinels into CreateOpts — omit the option to get the FS default"],"exampleFix":"// before\nfs.create(out, CreateOpts.blockSize(conf.getLong(\"my.block.size\", 0)));\n// after\nlong bs = conf.getLongBytes(\"my.block.size\", fs.getDefaultBlockSize(out));\nfs.create(out, CreateOpts.blockSize(bs));","handlingStrategy":"validation","validationCode":"long bs = conf.getLongBytes(\"my.block.size\", fs.getDefaultBlockSize(out));\nif (bs <= 0) throw new IllegalArgumentException(\"block size must be > 0\");\nfs.create(out, CreateOpts.blockSize(bs));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve block size from config with a positive FS default","Never forward -1 sentinels into CreateOpts","Omit the option to take the filesystem default"],"tags":["create-options","block-size","illegal-argument","validation"],"backgroundTag":"invalid-block-size","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}