MuntashirAkon/AppManager · error · IOException

No current entry to close

Error message

No current entry to close

What it means

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.

Solutions

  1. Call closeArchiveEntry exactly once per putArchiveEntry.
  2. Use a boolean flag to make finally-block closes idempotent.
  3. Restructure so entry open/close lives in one tightly scoped try/finally.

Example fix

// before
tar.closeArchiveEntry();
tar.closeArchiveEntry(); // second call throws
// after
boolean entryOpen = false;
tar.putArchiveEntry(entry); entryOpen = true;
try { tar.write(data); } finally { if (entryOpen) { tar.closeArchiveEntry(); entryOpen = false; } }
Defensive patterns

Strategy: try-catch

Validate before calling

// idempotent close
if (entryOpen) { tar.closeArchiveEntry(); entryOpen = false; }

Try / catch

try {
    tar.closeArchiveEntry();
} catch (IOException e) {
    if (!"No current entry to close".equals(e.getMessage())) throw e;
    // no entry open: safe to ignore in cleanup paths
}

Prevention

When it happens

Trigger: Calling closeArchiveEntry twice for one entry; calling it before any putArchiveEntry; calling it after a previous closeArchiveEntry already succeeded.

Common situations: Defensive close calls in catch/finally blocks; loops that close once per iteration but put the entry once; copy-pasted close logic.

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/6357fe340a4fe36b. Report an issue: GitHub.

Appendix: source

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

            haveUnclosedEntry = true;
        }
    }

    /**
     * Close an entry. This method MUST be called for all file entries that contain data. The reason
     * is that we must buffer data written to the stream in order to satisfy the buffer's record
     * based writes. Thus, there may be data fragments still being assembled that must be written to
     * the output stream before this entry is closed and the next entry written.
     *
     * @throws IOException on error
     */
    @Override
    public void closeArchiveEntry() throws IOException {
        if (finished) {
            throw new IOException("Stream has already been finished");
        }
        if (!haveUnclosedEntry) {
            throw new IOException("No current entry to close");
        }
        out.flushBlock();
        if (currBytes < currSize) {
            throw new IOException("Entry '" + currName + "' closed at '"
                + currBytes
                + "' before the '" + currSize
                + "' bytes specified in the header were written");
        }
        recordsWritten += (int) (currSize / RECORD_SIZE);
        if (0 != currSize % RECORD_SIZE) {
            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

View on GitHub (pinned to 0152f468fc)