{"record":{"id":"60b28cfc69b46bff","repo":"MuntashirAkon/AppManager","slug":"stream-closed","errorCode":null,"errorMessage":"Stream closed","messagePattern":"Stream closed","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java","lineNumber":125,"sourceCode":"     *             if {@code in == null}, the stream content is malformed, or an I/O error occurs.\n     */\n    public BZip2CompressorInputStream(final InputStream in, final boolean decompressConcatenated) throws IOException {\n        this.bin = new BitInputStream(in == System.in ? new CloseShieldFilterInputStream(in) : in,\n                ByteOrder.BIG_ENDIAN);\n        this.decompressConcatenated = decompressConcatenated;\n\n        init(true);\n        initBlock();\n    }\n\n    @Override\n    public int read() throws IOException {\n        if (this.bin != null) {\n            final int r = read0();\n            count(r < 0 ? -1 : 1);\n            return r;\n        }\n        throw new IOException(\"Stream closed\");\n    }\n\n    /*\n     * (non-Javadoc)\n     *\n     * @see java.io.InputStream#read(byte[], int, int)\n     */\n    @Override\n    public int read(final byte[] dest, final int offs, final int len)\n            throws IOException {\n        if (offs < 0) {\n            throw new IndexOutOfBoundsException(\"offs(\" + offs + \") < 0.\");\n        }\n        if (len < 0) {\n            throw new IndexOutOfBoundsException(\"len(\" + len + \") < 0.\");\n        }\n        if (offs + len > dest.length) {\n            throw new IndexOutOfBoundsException(\"offs(\" + offs + \") + len(\"","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java#L107-L143","documentation":"BZip2CompressorInputStream.read() throws IOException(\"Stream closed\") when read() is called after the stream has been closed (internal bin reference is null). InputStream.close() nulls the underlying decoder, and any subsequent read fails.","triggerScenarios":"Calling read() (single-byte or array variants) on a BZip2CompressorInputStream after close(); often from double-close followed by read, or sharing one stream across threads after one closed it.","commonSituations":"Try-with-resources accidentally covering code that re-reads the stream; caching the stream for later use after a close; concurrent access where one consumer closes early.","solutions":["Don't read after close(); restructure code so all reads occur inside the try-with-resources block","Remove duplicate/extra close() calls on the same stream","Reopen a new BZip2CompressorInputStream from the source if more data is needed","Guard concurrent access: one owner per stream, or synchronize close/read"],"exampleFix":"// before\nBZip2CompressorInputStream s = new BZip2CompressorInputStream(fis);\ns.close();\nint b = s.read(); // IOException: Stream closed\n// after\ntry (BZip2CompressorInputStream s = new BZip2CompressorInputStream(fis)) {\n    int b = s.read();\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    int b = bzipStream.read();\n} catch (IOException e) {\n    if (\"Stream closed\".equals(e.getMessage())) {\n        throw new IllegalStateException(\"Read attempted after close(); reopen the stream\", e);\n    }\n    throw e;\n}","preventionTips":["Scope all reads inside try-with-resources","Never cache and reuse a stream after close; create a new one from the source","Give each thread its own decompressor stream instance"],"tags":["bzip2","stream-closed","io","lifecycle"],"backgroundTag":"invalid-state-transition","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"}