{"record":{"id":"87644161ca6a3aae","repo":"MuntashirAkon/AppManager","slug":"no-current-tar-entry","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/TarArchiveInputStream.java","lineNumber":712,"sourceCode":"     * @param buf The buffer into which to place bytes read.\n     * @param offset The offset at which to place bytes read.\n     * @param numToRead The number of bytes to read.\n     * @return The number of bytes read, or -1 at EOF.\n     * @throws IOException on error\n     */\n    @Override\n    public int read(final byte[] buf, final int offset, int numToRead) throws IOException {\n        if (numToRead == 0) {\n            return 0;\n        }\n    \tint totalRead = 0;\n\n        if (isAtEOF() || isDirectory()) {\n            return -1;\n        }\n\n        if (currEntry == null) {\n            throw new IllegalStateException(\"No current tar entry\");\n        }\n\n        if (!currEntry.isSparse()) {\n            if (entryOffset >= entrySize) {\n                return -1;\n            }\n        } else {\n            // for sparse entries, there are actually currEntry.getRealSize() bytes to read\n            if (entryOffset >= currEntry.getRealSize()) {\n                return -1;\n            }\n        }\n\n        numToRead = Math.min(numToRead, available());\n\n        if (currEntry.isSparse()) {\n            // for sparse entries, we need to read them in another way\n            totalRead = readSparse(buf, offset, numToRead);","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java#L694-L730","documentation":"Thrown by TarArchiveInputStream.read when there is no current entry to read from. Reading is positional: you must first advance the stream with getNextEntry/getNextTarEntry before calling read; otherwise the stream has no entry context.","triggerScenarios":"Calling read(byte[],int,int) before the first getNextEntry() call, after getNextEntry() returned null (EOF), or after close() — e.g. in getLongNameData when the entry state was lost.","commonSituations":"Reading entries without iterating via getNextTarEntry; reusing a stream object after exhausting it; off-by-one loop conditions that read one extra time after null.","solutions":["Call getNextTarEntry()/getNextEntry() and check for non-null before every read loop","Stop the read loop as soon as getNextEntry() returns null","Create a new TarArchiveInputStream instead of reusing an exhausted one","Guard reads with a currEntry != null check (which is what read() itself does internally)"],"exampleFix":"// before\nTarArchiveEntry entry = tin.getNextTarEntry();\nbyte[] data = new byte[1024];\ntin.read(data); // crashes if entry was null\n// after\nTarArchiveEntry entry = tin.getNextTarEntry();\nif (entry != null) {\n    byte[] data = new byte[1024];\n    tin.read(data);\n}","handlingStrategy":"validation","validationCode":"TarArchiveEntry entry = tin.getNextTarEntry();\nif (entry == null) { throw new IOException(\"no entry available to read\"); }","typeGuard":"boolean hasCurrentEntry(TarArchiveInputStream in, TarArchiveEntry current) { return current != null; }","tryCatchPattern":"try {\n    tin.read(buf, 0, buf.length);\n} catch (IllegalStateException e) {\n    if (\"No current tar entry\".equals(e.getMessage())) {\n        throw new IOException(\"Call getNextTarEntry() before reading\", e);\n    }\n    throw e;\n}","preventionTips":["Always iterate with getNextTarEntry() and check for null before reading","Never reuse an exhausted TarArchiveInputStream","Structure read loops as: while ((e = in.getNextTarEntry()) != null) { readFully(e); }"],"tags":["tar","invalid-state","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"}