{"record":{"id":"fa7856928b1997a1","repo":"apache/flink","slug":"premeture-eof-from-inputstream","errorCode":null,"errorMessage":"Premeture EOF from inputStream","messagePattern":"Premeture EOF from inputStream","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/IOUtils.java","lineNumber":165,"sourceCode":"            }\n            totalRead += read;\n        }\n        return totalRead;\n    }\n\n    /**\n     * Similar to readFully(). Skips bytes in a loop.\n     *\n     * @param in The InputStream to skip bytes from\n     * @param len number of bytes to skip\n     * @throws IOException if it could not skip requested number of bytes for any reason (including\n     *     EOF)\n     */\n    public static void skipFully(final InputStream in, long len) throws IOException {\n        while (len > 0) {\n            final long ret = in.skip(len);\n            if (ret < 0) {\n                throw new IOException(\"Premeture EOF from inputStream\");\n            }\n            len -= ret;\n        }\n    }\n\n    // ------------------------------------------------------------------------\n    //  Silent I/O cleanup / closing\n    // ------------------------------------------------------------------------\n\n    /**\n     * Close the AutoCloseable objects and <b>ignore</b> any {@link Exception} or null pointers.\n     * Must only be used for cleanup in exception handlers.\n     *\n     * @param log the log to record problems to at debug level. Can be <code>null</code>.\n     * @param closeables the objects to close\n     */\n    public static void cleanup(final Logger log, final AutoCloseable... closeables) {\n        for (AutoCloseable c : closeables) {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/IOUtils.java#L147-L183","documentation":"IOUtils.skipFully loops in.skip(len) until the requested count is skipped, throwing IOException(\"Premeture EOF from inputStream\") — typo of 'Premature' — when skip returns a negative value. Note the JDK contract says InputStream.skip never returns negative (it returns 0 at EOF), so in practice a conforming stream at EOF causes an infinite loop here; the throw fires only with non-conforming custom streams that return negative on EOF.","triggerScenarios":"Calling IOUtils.skipFully on a custom InputStream whose skip() implementation returns -1 at end of stream (some hand-rolled or wrapped streams do this), or on a stream already at/past EOF with such an implementation.","commonSituations":"Wrapping Flink's FSDataInputStream or user streams in adapters where skip is overridden with `return -1;` at EOF; deserialization code skipping over padding in truncated input.","solutions":["Fix the custom stream's skip(): at EOF return 0 (per InputStream contract) or throw EOFException, never a negative value","Check available()/read() for EOF before skipping, or verify the byte count you plan to skip matches what was written","If the underlying data is truncated, re-fetch it — the skip demand exceeding remaining bytes indicates corruption upstream"],"exampleFix":"// before (custom stream)\n@Override public long skip(long n) throws IOException {\n    if (atEof) return -1; // triggers 'Premeture EOF'\n    ...\n}\n// after\n@Override public long skip(long n) throws IOException {\n    if (atEof) return 0;\n    ...\n}","handlingStrategy":"validation","validationCode":"// contract check for custom streams: skip() must never return negative\nif (n <= 0 || streamAtEof) return 0; // inside your skip() override","typeGuard":null,"tryCatchPattern":"try { IOUtils.skipFully(in, n); } catch (IOException e) { /* EOF signaled by negative skip: treat as truncation */ }","preventionTips":["Implement skip() per the InputStream contract: 0 at EOF, never negative","Skip only byte ranges you know were written"],"tags":["io","stream","custom-stream","eof"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}