{"record":{"id":"3852fba6b71a3bef","repo":"apache/hadoop","slug":"blocksize-9","errorCode":null,"errorMessage":"blockSize({}) > 9","messagePattern":"blockSize\\((.+?)\\) > 9","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":636,"sourceCode":"  *             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\");\n    }\n  }\n\n  private void writeRun() throws IOException {","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/bzip2/CBZip2OutputStream.java#L618-L654","documentation":"The upper-bound half of CBZip2OutputStream's constructor validation: blockSize must not exceed 9 (MAX_BLOCKSIZE), because the bzip2 format encodes the block size as a single digit ('BZh1'..'BZh9') and the decoder allocates blockSize*100000-byte buffers accordingly. Anything above 9 throws IllegalArgumentException(\"blockSize(...) > 9\") before any output is written.","triggerScenarios":"new CBZip2OutputStream(out, blockSize) with a value like 10..900000: callers passing the block size in bytes (e.g. 900000) instead of the 1-9 code, or config/multiplier arithmetic (blockSize * 100) exceeding the range.","commonSituations":"Unit confusion between 'blocksize' codes (1-9) and byte sizes (100k-900k); copy-paste from tools that accept --bzip2-blocksize=900k; properties scaled twice; upgraded code that used to accept raw byte counts.","solutions":["Pass the format-level code, not bytes: divide byte sizes by 100000 and clamp to 1..9.","Clamp defensively: Math.min(CBZip2OutputStream.MAX_BLOCKSIZE, Math.max(CBZip2OutputStream.MIN_BLOCKSIZE, blockSize)).","Use Bzip2Factory/Configuration plumbing ('bzip2.compress.blocksize', default 9) instead of hand-passing numbers.","Add a startup assertion/property check that names the bad value so the fix lands in config, not a stack trace at first write."],"exampleFix":"// before\nnew CBZip2OutputStream(out, 900000); // meant 900k bytes, passed raw\n\n// after\nint bs = Math.max(1, Math.min(9, desiredBytes / 100000));\nnew CBZip2OutputStream(out, bs); // bs == 9","handlingStrategy":"validation","validationCode":"int bs = (desiredBlockBytes + 99999) / 100000; // bytes -> 1..9 code\nbs = Math.max(1, Math.min(9, bs));\nnew CBZip2OutputStream(out, bs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember the 1-9 code means blockSize * 100000 bytes; never pass byte counts.","Clamp at the config boundary so a bad property fails with a clear message, not a constructor stack trace.","Unit-test construction for boundary values 1 and 9."],"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"}