{"record":{"id":"9a07482a3d916b29","repo":"MuntashirAkon/AppManager","slug":"closed","errorCode":null,"errorMessage":"Closed","messagePattern":"Closed","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java","lineNumber":383,"sourceCode":"        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\n    /**\n     * Writes the current byte to the buffer, run-length encoding it\n     * if it has been repeated at least four times (the first step\n     * RLEs sequences of four identical bytes).\n     *\n     * <p>Flushes the current block before writing data if it is\n     * full.</p>\n     *\n     * <p>\"write to the buffer\" means adding to data.buffer starting\n     * two steps \"after\" this.last - initially starting at index 1\n     * (not 0) - and updating this.last to point to the last index\n     * written minus 1.</p>\n     */\n    private void writeRun() throws IOException {","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java#L365-L401","documentation":"write(int) checks whether the output stream has already been closed; writing after close() is an invalid state and throws IOException(\"Closed\"). A closed BZip2CompressorOutputStream has finalized the bzip2 stream and cannot accept more data.","triggerScenarios":"Calling write(byte), write(byte[]), or close()-dependent wrappers after close() was invoked — e.g. writing via the same reference twice, try-with-resources followed by manual writes, or a copied reference to a stream closed elsewhere.","commonSituations":"Double-close in layered stream code, buffering writes after try-with-resources scope ends, a utility method closing the caller's stream then the caller writing more, caching the stream in a field after a completed unit of work.","solutions":["Stop writing after close(); restructure so close() happens only when all data is written.","Open a new BZip2CompressorOutputStream for additional data instead of reusing a closed one.","Ensure only one owner closes the stream (try-with-resources around the entire write path).","Guard with an isClosed()/closed flag check before writing if lifecycle is complex."],"exampleFix":"// before\ntry (BZip2CompressorOutputStream b = new BZip2CompressorOutputStream(fos)) {\n    b.write(header);\n}\nb.write(footer); // stream already closed -> IOException: Closed\n// after\ntry (BZip2CompressorOutputStream b = new BZip2CompressorOutputStream(fos)) {\n    b.write(header);\n    b.write(footer);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if (!closed) {\n    try { stream.write(b); } catch (IOException e) {\n        if (\"Closed\".equals(e.getMessage())) throw new IllegalStateException(\"write after close\", e);\n        throw e;\n    }\n}","preventionTips":["Use try-with-resources so all writes happen inside the open scope","Have a single owner responsible for closing the stream","Never cache and reuse compressor streams after a completed unit of work","Track closed state in wrapper classes and fail early with a clear error"],"tags":["io","bzip2","closed-stream","lifecycle"],"backgroundTag":"stream-already-closed","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"}