{"record":{"id":"37316b158da4dc12","repo":"MuntashirAkon/AppManager","slug":"blocksize-blocksize-9","errorCode":null,"errorMessage":"blockSize(\" + blockSize + \") > 9","messagePattern":"blockSize\\(\" \\+ blockSize \\+ \"\\) > 9","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java","lineNumber":369,"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 &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        }\n        write0(b);\n    }\n","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java#L351-L387","documentation":"Argument-validation guard in the BZip2CompressorOutputStream constructor: the blockSize parameter (in 100k units) must be between 1 and 9 (MIN_BLOCKSIZE..MAX_BLOCKSIZE); the caller passed a value above 9 (the companion guard handles values below 1), so the stream refuses to allocate an out-of-range Bzip2 block size. Faulty input: the blockSize argument.","triggerScenarios":"new BZip2CompressorOutputStream(out, blockSize) with blockSize >= 10, e.g. a user entering '10' or a config value meant as megabytes rather than the 1–9 block-size code.","commonSituations":"Confusing blockSize100k (1–9) with byte sizes; copying settings from other libraries that take bytes; UI not constraining input to 1–9.","solutions":["Clamp the value into the 1–9 range before constructing the stream.","Use the one-argument constructor for the default block size (9).","If users specify sizes in bytes/MB, convert to the bzip2 level: level = (int) Math.min(9, Math.max(1, sizeBytes / 100_000))."],"exampleFix":"// before\nnew BZip2CompressorOutputStream(os, 900_000); // wrong unit\n// after\nint level = Math.max(1, Math.min(9, 900_000 / 100_000)); // = 9\nnew BZip2CompressorOutputStream(os, level);","handlingStrategy":"validation","validationCode":"int safeLevel = Math.max(1, Math.min(9, userLevel));\nBZip2CompressorOutputStream out = new BZip2CompressorOutputStream(os, safeLevel);","typeGuard":null,"tryCatchPattern":"try {\n    out = new BZip2CompressorOutputStream(os, userLevel);\n} catch (IllegalArgumentException e) {\n    throw new BadConfigException(\"bzip2 blockSize must be 1-9\", e);\n}","preventionTips":["Clamp user/config-supplied levels into 1..9","Restrict UI inputs to 1–9","Don't confuse blockSize100k with byte-based sizes from other libraries","Add a unit test covering boundary values 0, 1, 9, 10"],"tags":["bzip2","compression","illegal-argument","value-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}