{"record":{"id":"6357fe340a4fe36b","repo":"MuntashirAkon/AppManager","slug":"no-current-entry-to-close","errorCode":null,"errorMessage":"No current entry to close","messagePattern":"No current entry to close","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java","lineNumber":410,"sourceCode":"            haveUnclosedEntry = true;\n        }\n    }\n\n    /**\n     * Close an entry. This method MUST be called for all file entries that contain data. The reason\n     * is that we must buffer data written to the stream in order to satisfy the buffer's record\n     * based writes. Thus, there may be data fragments still being assembled that must be written to\n     * the output stream before this entry is closed and the next entry written.\n     *\n     * @throws IOException on error\n     */\n    @Override\n    public void closeArchiveEntry() throws IOException {\n        if (finished) {\n            throw new IOException(\"Stream has already been finished\");\n        }\n        if (!haveUnclosedEntry) {\n            throw new IOException(\"No current entry to close\");\n        }\n        out.flushBlock();\n        if (currBytes < currSize) {\n            throw new IOException(\"Entry '\" + currName + \"' closed at '\"\n                + currBytes\n                + \"' before the '\" + currSize\n                + \"' bytes specified in the header were written\");\n        }\n        recordsWritten += (int) (currSize / RECORD_SIZE);\n        if (0 != currSize % RECORD_SIZE) {\n            recordsWritten++;\n        }\n        haveUnclosedEntry = false;\n    }\n\n    /**\n     * Writes bytes to the current tar archive entry. This method is aware of the current entry and\n     * will throw an exception if you attempt to write bytes past the length specified for the","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java#L392-L428","documentation":"closeArchiveEntry throws IOException when there is no currently open entry, i.e. it was called without a preceding putArchiveEntry or after the previous entry was already closed. The library tracks this with the haveUnclosedEntry flag.","triggerScenarios":"Calling closeArchiveEntry twice for one entry; calling it before any putArchiveEntry; calling it after a previous closeArchiveEntry already succeeded.","commonSituations":"Defensive close calls in catch/finally blocks; loops that close once per iteration but put the entry once; copy-pasted close logic.","solutions":["Call closeArchiveEntry exactly once per putArchiveEntry.","Use a boolean flag to make finally-block closes idempotent.","Restructure so entry open/close lives in one tightly scoped try/finally."],"exampleFix":"// before\ntar.closeArchiveEntry();\ntar.closeArchiveEntry(); // second call throws\n// after\nboolean entryOpen = false;\ntar.putArchiveEntry(entry); entryOpen = true;\ntry { tar.write(data); } finally { if (entryOpen) { tar.closeArchiveEntry(); entryOpen = false; } }","handlingStrategy":"try-catch","validationCode":"// idempotent close\nif (entryOpen) { tar.closeArchiveEntry(); entryOpen = false; }","typeGuard":null,"tryCatchPattern":"try {\n    tar.closeArchiveEntry();\n} catch (IOException e) {\n    if (!\"No current entry to close\".equals(e.getMessage())) throw e;\n    // no entry open: safe to ignore in cleanup paths\n}","preventionTips":["Make finally-block closes idempotent with a flag","Close each entry exactly once","Scope entry open/close to a single method"],"tags":["tar","stream-state","unclosed-entry","api-misuse"],"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-23T08:17:48.524Z"}