{"record":{"id":"dc539fd00a07f5eb","repo":"apache/hadoop","slug":"replication-must-be-greater-than-0","errorCode":null,"errorMessage":"Replication must be greater than 0","messagePattern":"Replication 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":91,"sourceCode":"    }\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    }\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    }","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Options.java#L73-L109","documentation":"Options.CreateOpts.ReplicationFactor validates that the replication factor passed to FileSystem.create(path, CreateOpts.replication(rf), ...) is a positive short; rf <= 0 throws IllegalArgumentException at option construction time.","triggerScenarios":"CreateOpts.replication(rf) with rf <= 0 — e.g. dfs.replication configured to 0 or negative, a cast from a defaulted int config, or a computed replication of 0 for tiny/test clusters.","commonSituations":"Misconfigured replication in site XML, property typos falling back to 0, code paths propagating user input unchecked.","solutions":["Fix the replication config value (dfs.replication) to a positive integer","Default to fs.getDefaultReplication(path) when the caller has no explicit value","Validate replication > 0 before building CreateOpts"],"exampleFix":"// before\nCreateOpts.replication((short) conf.getInt(\"my.repl\", -1))\n// after\nshort repl = (short) Math.max(1, conf.getInt(\"my.repl\", fs.getDefaultReplication(out)));\nCreateOpts.replication(repl)","handlingStrategy":"validation","validationCode":"short repl = (short) Math.max(1,\n    conf.getInt(\"my.repl\", fs.getDefaultReplication(out)));\nif (repl <= 0) throw new IllegalArgumentException(\"replication must be > 0\");\nfs.create(out, CreateOpts.replication(repl));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fix dfs.replication-style config to a positive integer","Default to fs.getDefaultReplication(path) when unspecified","Validate short casts from config before building options"],"tags":["create-options","replication","illegal-argument","validation"],"backgroundTag":"invalid-replication-factor","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}