MuntashirAkon/AppManager · error · IllegalStateException

No current tar entry

Error message

No current tar entry

What it means

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.

Solutions

  1. Call putArchiveEntry(new TarArchiveEntry(name)) before writing bytes, and closeArchiveEntry afterwards.
  2. Ensure per-file loops open an entry for every file written.
  3. Move any preamble data into a dedicated entry rather than writing it raw.

Example fix

// before
tar.write(headerBytes); // no entry open -> IllegalStateException
// after
tar.putArchiveEntry(new TarArchiveEntry("preamble.txt"));
tar.write(headerBytes);
tar.closeArchiveEntry();
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure an entry is open before writing
if (!entryOpen) throw new IllegalStateException("call putArchiveEntry() before write()");

Try / catch

try {
    tar.write(buf, 0, len);
} catch (IllegalStateException e) {
    if (!"No current tar entry".equals(e.getMessage())) throw e;
    // open an entry and retry, or fix call order
}

Prevention

When it happens

Trigger: Calling write(byte[], int, int) with haveUnclosedEntry == false: before the first putArchiveEntry, after closeArchiveEntry, or after finish.

Common situations: Writing archive-level 'headers' directly to the stream; writing after closing an entry; interleaving logic that forgets to open a new entry per file.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/9b83061d106fd4ca. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java:439

            recordsWritten++;
        }
        haveUnclosedEntry = false;
    }

    /**
     * Writes bytes to the current tar archive entry. This method is aware of the current entry and
     * will throw an exception if you attempt to write bytes past the length specified for the
     * current entry.
     *
     * @param wBuf The buffer to write to the archive.
     * @param wOffset The offset in the buffer from which to get bytes.
     * @param numToWrite The number of bytes to write.
     * @throws IOException on error
     */
    @Override
    public void write(final byte[] wBuf, final int wOffset, final int numToWrite) throws IOException {
        if (!haveUnclosedEntry) {
            throw new IllegalStateException("No current tar entry");
        }
        if (currBytes + numToWrite > currSize) {
            throw new IOException("Request to write '" + numToWrite
                + "' bytes exceeds size in header of '"
                + currSize + "' bytes for entry '"
                + currName + "'");
        }
        out.write(wBuf, wOffset, numToWrite);
        currBytes += numToWrite;
    }

    /**
     * Writes a PAX extended header with the given map as contents.
     *
     * @since 1.4
     */
    void writePaxHeaders(final TarArchiveEntry entry,
        final String entryName,

View on GitHub (pinned to 0152f468fc)