{"record":{"id":"3d23d2bf0e26df0f","repo":"apache/hadoop","slug":"blocksize-1","errorCode":null,"errorMessage":"blockSize({}) < 1","messagePattern":"blockSize\\((.+?)\\) < 1","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/bzip2/CBZip2OutputStream.java","lineNumber":632,"sourceCode":"  * @param blockSize\n  *            the blockSize as 100k units.\n  *\n  * @throws IOException\n  *             if an I/O error occurs in the specified stream.\n  * @throws IllegalArgumentException\n  *             if {@code (blockSize < 1) || (blockSize > 9)}\n  * @throws NullPointerException\n  *             if {@code out == null}.\n  *\n  * @see #MIN_BLOCKSIZE\n  * @see #MAX_BLOCKSIZE\n  */\n  public CBZip2OutputStream(final OutputStream out, final int blockSize)\n      throws IOException {\n    super();\n\n    if (blockSize < 1) {\n      throw new IllegalArgumentException(\"blockSize(\" + blockSize\n          + \") < 1\");\n    }\n    if (blockSize > 9) {\n      throw new IllegalArgumentException(\"blockSize(\" + blockSize\n          + \") > 9\");\n    }\n\n    this.blockSize100k = blockSize;\n    this.out = out;\n    init();\n  }\n\n  @Override\n  public void write(final int b) throws IOException {\n    if (this.out != null) {\n      write0(b);\n    } else {\n      throw new IOException(\"closed\");","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/bzip2/CBZip2OutputStream.java#L614-L650","documentation":"CBZip2OutputStream's constructor validates the blockSize argument, which selects the compression block size as blockSize * 100000 bytes and must be within MIN_BLOCKSIZE(1)..MAX_BLOCKSIZE(9). A value below 1 is rejected immediately with IllegalArgumentException(\"blockSize(...) < 1\"). This is a pure API-misuse guard: the compressor cannot be built with a non-positive block size.","triggerScenarios":"new CBZip2OutputStream(out, blockSize) called with 0 or a negative number: a Configuration property parsed to 0 (e.g. 'bzip2.compress.blocksize' unset returning a bad default in caller code), a computed value underflowing, or a literal mistake.","commonSituations":"Block size read from job/config XML where a missing key was defaulted to 0 by hand-rolled getInt code; values derived from user input or arithmetic (size/100000 with small inputs) going negative; porting code that assumed a different blockSize unit (900000 vs 9).","solutions":["Clamp the value to the documented range before constructing: Math.max(CBZip2OutputStream.MIN_BLOCKSIZE, Math.min(CBZip2OutputStream.MAX_BLOCKSIZE, blockSize)).","If deriving from Configuration, use a sane default (Bzip2Factory reads 'bzip2.compress.blocksize', defaulting to 9) and validate the parsed integer.","Consider the built-in helper CBZip2OutputStream.chooseBlockSize(inputLength) which returns a legal value for a given input size.","Fail fast with a clear config error message naming the offending property and value."],"exampleFix":"// before\nint bs = conf.getInt(\"bzip2.compress.blocksize\", 0);\nnew CBZip2OutputStream(out, bs); // IllegalArgumentException: blockSize(0) < 1\n\n// after\nint bs = conf.getInt(\"bzip2.compress.blocksize\",\n                      CBZip2OutputStream.MAX_BLOCKSIZE);\nbs = Math.max(CBZip2OutputStream.MIN_BLOCKSIZE,\n       Math.min(CBZip2OutputStream.MAX_BLOCKSIZE, bs));\nnew CBZip2OutputStream(out, bs);","handlingStrategy":"validation","validationCode":"int bs = Math.max(CBZip2OutputStream.MIN_BLOCKSIZE,\n                  Math.min(CBZip2OutputStream.MAX_BLOCKSIZE, requested));\nnew CBZip2OutputStream(out, bs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always source blockSize from Bzip2Factory/Configuration ('bzip2.compress.blocksize', default 9) rather than raw numbers.","Use CBZip2OutputStream.chooseBlockSize(inputLength) for size-derived values.","Validate config-derived ints at startup with named-property error messages."],"tags":["bzip2","compression","invalid-argument","constructor","hadoop"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}