{"record":{"id":"f12c5da39f39d40f","repo":"Tencent/tinker","slug":"no-active-entry","errorCode":null,"errorMessage":"No active entry","messagePattern":"No active entry","errorType":"exception","errorClass":"ZipException","httpStatus":null,"severity":"error","filePath":"third-party/tinker-ziputils/src/main/java/com/tencent/tinker/ziputils/ziputil/TinkerZipOutputStream.java","lineNumber":576,"sourceCode":"            this.commentBytes = BYTE;\n            return;\n        }\n        byte[] newCommentBytes = comment.getBytes(StandardCharsets.UTF_8);\n        checkSizeIsWithinShort(\"Comment\", newCommentBytes);\n        this.commentBytes = newCommentBytes;\n    }\n\n    /**\n     * Writes data for the current entry to the underlying stream.\n     *\n     * @throws IOException\n     *                If an error occurs writing to the stream\n     */\n    @Override\n    public void write(byte[] buffer, int offset, int byteCount) throws IOException {\n        Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);\n        if (currentEntry == null) {\n            throw new ZipException(\"No active entry\");\n        }\n        /*final long totalBytes = crc.tbytes + byteCount;\n        if ((totalBytes > Zip64.MAX_ZIP_ENTRY_AND_ARCHIVE_SIZE) && !currentEntryNeedsZip64) {\n            throw new IOException(\"Zip entry size (\" + totalBytes +\n                    \" bytes) cannot be represented in the zip format (needs Zip64).\" +\n                    \" Set the entry length using ZipEntry#setLength to use Zip64 where necessary.\");\n        }*/\n        if (currentEntry.getMethod() == STORED) {\n            out.write(buffer, offset, byteCount);\n        } else {\n            out.write(buffer, offset, byteCount);\n        }\n        // crc.update(buffer, offset, byteCount);\n    }\n    private void checkOpen() throws IOException {\n        if (cDir == null) {\n            throw new IOException(\"Stream is closed\");\n        }","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/third-party/tinker-ziputils/src/main/java/com/tencent/tinker/ziputils/ziputil/TinkerZipOutputStream.java#L558-L594","documentation":"TinkerZipOutputStream.write(byte[], int, int) throws ZipException(\"No active entry\") when currentEntry == null — i.e. there is no entry between putNextEntry() and closeEntry(). The zip format requires all payload bytes to belong to a local file header, so writing outside an entry would produce a corrupt archive and is rejected eagerly.","triggerScenarios":"Calling write() before the first putNextEntry(); calling write() after closeEntry() for the previous entry but before putNextEntry() for the next; calling write() after finish() has been reached (finish closes the current entry, clearing currentEntry).","commonSituations":"Copy loops where the source stream is exhausted or the loop body reordered so write happens outside the entry bracket; error paths that call closeEntry() then continue flushing remaining buffers; writing after close().","solutions":["Check the call ordering: every write() must sit between a successful putNextEntry(e) and the matching closeEntry().","Guard copy helpers with a boolean 'entryOpen' flag (set true on putNextEntry, false on closeEntry) and skip/log writes when it is false.","If this appears after finish(), the stream is done — create a new TinkerZipOutputStream instead of reusing it."],"exampleFix":"// before\nzos.write(buffer, 0, n); // before any putNextEntry\nTinkerZipEntry e = new TinkerZipEntry(\"a.txt\");\nzos.putNextEntry(e);\n\n// after\nTinkerZipEntry e = new TinkerZipEntry(\"a.txt\");\nzos.putNextEntry(e);\nzos.write(buffer, 0, n);\nzos.closeEntry();","handlingStrategy":"validation","validationCode":"// maintain explicit entry-open state in copy loops\nclass ZipCopier {\n    private boolean entryOpen = false;\n    void open(TinkerZipOutputStream zos, TinkerZipEntry e) throws IOException {\n        zos.putNextEntry(e); entryOpen = true;\n    }\n    void write(TinkerZipOutputStream zos, byte[] b, int n) throws IOException {\n        if (!entryOpen) throw new IllegalStateException(\"write outside entry\");\n        zos.write(b, 0, n);\n    }\n    void close(TinkerZipOutputStream zos) throws IOException {\n        if (entryOpen) { zos.closeEntry(); entryOpen = false; }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always bracket writes with putNextEntry/closeEntry in a single try block","Review loop bodies for 'continue'/'break' paths that skip putNextEntry but still write"],"tags":["zip","java","tinker","stream-misuse"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}