{"record":{"id":"c80819717a015c75","repo":"MuntashirAkon/AppManager","slug":"blocksize-blocksize-1","errorCode":null,"errorMessage":"blockSize(\" + blockSize + \") < 1","messagePattern":"blockSize\\(\" \\+ blockSize \\+ \"\\) < 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java","lineNumber":366,"sourceCode":"     *\n     * @param out\n     *            the destination stream.\n     * @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 &lt; 1) || (blockSize &gt; 9)</code>.\n     * @throws NullPointerException\n     *             if <code>out == null</code>.\n     *\n     * @see #MIN_BLOCKSIZE\n     * @see #MAX_BLOCKSIZE\n     */\n    public BZip2CompressorOutputStream(final OutputStream out, final int blockSize) throws IOException {\n        if (blockSize < 1) {\n            throw new IllegalArgumentException(\"blockSize(\" + blockSize + \") < 1\");\n        }\n        if (blockSize > 9) {\n            throw new IllegalArgumentException(\"blockSize(\" + blockSize + \") > 9\");\n        }\n\n        this.blockSize100k = blockSize;\n        this.out = out;\n\n        /* 20 is just a paranoia constant */\n        this.allowableBlockSize = (this.blockSize100k * BZip2Constants.BASEBLOCKSIZE) - 20;\n        init();\n    }\n\n    @Override\n    public void write(final int b) throws IOException {\n        if (closed) {\n            throw new IOException(\"Closed\");\n        }","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java#L348-L384","documentation":"The BZip2CompressorOutputStream(out, blockSize) constructor requires a blockSize100k parameter between 1 and 9 (meaning 100k–900k blocks). Passing 0 or a negative number is rejected immediately with this IllegalArgumentException — it is a programming/config error, not an I/O problem.","triggerScenarios":"new BZip2CompressorOutputStream(out, 0) or any negative blockSize; typically blockSize read from config/env that defaulted to 0.","commonSituations":"Config property like 'compress.blocksize' missing or parsed to 0, user-supplied value not clamped, refactored code passing an uninitialized int.","solutions":["Pass a blockSize between 1 and 9, or use the single-argument constructor BZip2CompressorOutputStream(out) which uses the default.","Clamp or default invalid configured values before constructing (Math.max(1, Math.min(9, value))).","If blockSize comes from config, validate it at startup with a clear message."],"exampleFix":"// before\nint blockSize = Integer.parseInt(cfg.get(\"blocksize\")); // 0 when unset\nBZip2CompressorOutputStream out = new BZip2CompressorOutputStream(os, blockSize);\n// after\nint blockSize = Math.max(1, Math.min(9, Integer.parseInt(cfg.getOrDefault(\"blocksize\", \"9\"))));\nBZip2CompressorOutputStream out = new BZip2CompressorOutputStream(os, blockSize);","handlingStrategy":"validation","validationCode":"// validate before constructing\nif (blockSize < 1 || blockSize > 9)\n    throw new IllegalArgumentException(\"blockSize must be 1..9, got \" + blockSize);","typeGuard":null,"tryCatchPattern":"try {\n    out = new BZip2CompressorOutputStream(os, configuredBlockSize);\n} catch (IllegalArgumentException e) {\n    out = new BZip2CompressorOutputStream(os); // fall back to default\n    log.warn(\"bad blockSize config, using default\", e);\n}","preventionTips":["Validate compression-level config at startup","Prefer the single-argument constructor when the level is not user-controlled","Clamp external config into 1..9","Document that blockSize is the bzip2 level (100k units), not bytes"],"tags":["bzip2","compression","illegal-argument","configuration"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}