{"record":{"id":"9b83061d106fd4ca","repo":"MuntashirAkon/AppManager","slug":"no-current-tar-entry-tararchiveoutputstream","errorCode":null,"errorMessage":"No current tar entry","messagePattern":"No current tar entry","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java","lineNumber":439,"sourceCode":"            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\n     * current entry.\n     *\n     * @param wBuf The buffer to write to the archive.\n     * @param wOffset The offset in the buffer from which to get bytes.\n     * @param numToWrite The number of bytes to write.\n     * @throws IOException on error\n     */\n    @Override\n    public void write(final byte[] wBuf, final int wOffset, final int numToWrite) throws IOException {\n        if (!haveUnclosedEntry) {\n            throw new IllegalStateException(\"No current tar entry\");\n        }\n        if (currBytes + numToWrite > currSize) {\n            throw new IOException(\"Request to write '\" + numToWrite\n                + \"' bytes exceeds size in header of '\"\n                + currSize + \"' bytes for entry '\"\n                + currName + \"'\");\n        }\n        out.write(wBuf, wOffset, numToWrite);\n        currBytes += numToWrite;\n    }\n\n    /**\n     * Writes a PAX extended header with the given map as contents.\n     *\n     * @since 1.4\n     */\n    void writePaxHeaders(final TarArchiveEntry entry,\n        final String entryName,","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java#L421-L457","documentation":"TarArchiveOutputStream.write throws IllegalStateException when there is no open entry, because tar requires every data byte to belong to a header-declared entry. Writing before putArchiveEntry or after closeArchiveEntry is an API-usage bug in the caller, not a stream-corruption issue.","triggerScenarios":"Calling write(byte[], int, int) with haveUnclosedEntry == false: before the first putArchiveEntry, after closeArchiveEntry, or after finish.","commonSituations":"Writing archive-level 'headers' directly to the stream; writing after closing an entry; interleaving logic that forgets to open a new entry per file.","solutions":["Call putArchiveEntry(new TarArchiveEntry(name)) before writing bytes, and closeArchiveEntry afterwards.","Ensure per-file loops open an entry for every file written.","Move any preamble data into a dedicated entry rather than writing it raw."],"exampleFix":"// before\ntar.write(headerBytes); // no entry open -> IllegalStateException\n// after\ntar.putArchiveEntry(new TarArchiveEntry(\"preamble.txt\"));\ntar.write(headerBytes);\ntar.closeArchiveEntry();","handlingStrategy":"try-catch","validationCode":"// Ensure an entry is open before writing\nif (!entryOpen) throw new IllegalStateException(\"call putArchiveEntry() before write()\");","typeGuard":null,"tryCatchPattern":"try {\n    tar.write(buf, 0, len);\n} catch (IllegalStateException e) {\n    if (!\"No current tar entry\".equals(e.getMessage())) throw e;\n    // open an entry and retry, or fix call order\n}","preventionTips":["Always putArchiveEntry before write and closeArchiveEntry after","Wrap per-entry writes in a helper enforcing open/close","Never write raw bytes outside an entry"],"tags":["tar","stream-state","api-misuse","no-open-entry"],"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"}