{"record":{"id":"0c5b20792fc47f2e","repo":"apache/flink","slug":"could-not-skip-numbytes-bytes-0c5b20","errorCode":null,"errorMessage":"Could not skip {numBytes} bytes.","messagePattern":"Could not skip (.+?) bytes\\.","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java","lineNumber":376,"sourceCode":"                }\n            } else {\n                throw new IOException(\n                        \"Failed to serialize element. Serialized size (> \"\n                                + newLen\n                                + \" bytes) exceeds JVM heap space\",\n                        e);\n            }\n        }\n\n        System.arraycopy(this.buffer, 0, nb, 0, this.position);\n        this.buffer = nb;\n        this.wrapper = ByteBuffer.wrap(this.buffer);\n    }\n\n    @Override\n    public void skipBytesToWrite(int numBytes) throws IOException {\n        if (buffer.length - this.position < numBytes) {\n            throw new EOFException(\"Could not skip \" + numBytes + \" bytes.\");\n        }\n\n        this.position += numBytes;\n    }\n\n    @Override\n    public void write(DataInputView source, int numBytes) throws IOException {\n        if (buffer.length - this.position < numBytes) {\n            throw new EOFException(\"Could not write \" + numBytes + \" bytes. Buffer overflow.\");\n        }\n\n        source.readFully(this.buffer, this.position, numBytes);\n        this.position += numBytes;\n    }\n\n    public void setPosition(int position) {\n        Preconditions.checkArgument(\n                position >= 0 && position <= this.position, \"Position out of bounds.\");","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java#L358-L394","documentation":"Thrown by DataOutputSerializer.skipBytesToWrite(int) when the remaining buffer (buffer.length - position) is less than numBytes. Unlike write(), skipBytesToWrite does NOT auto-resize the buffer, so it is a hard failure when there is insufficient space. It is typically used to reserve placeholder bytes (e.g. a length prefix) that are back-filled later.","triggerScenarios":"Calling skipBytesToWrite(n) when buffer.length - position < n; commonly when reserving a length-prefix slot without first ensuring capacity.","commonSituations":"Back-patching a length field after writing content but on a too-small or fixed buffer; using skipBytesToWrite instead of write on a buffer sized only for the content; forgetting that skip does not grow the buffer.","solutions":["Ensure the buffer can hold position + numBytes before skipBytesToWrite (size the DataOutputSerializer generously or write first to trigger auto-resize).","Use write(source, n) or explicit writes (which auto-resize) instead of skipBytesToWrite when the content size is unknown.","Reserve the prefix slot before writing content so position stays within capacity."],"exampleFix":"// before\nout.skipBytesToWrite(4); // reserve length prefix, may overflow\n// ... write content ...\n\n// after: reserve prefix first while buffer is fresh\nout.skipBytesToWrite(4);\nint lenPos = out.length() - 4;\n// ... write content (auto-resizes) ...\nout.writeIntUnsafe(recordLen, lenPos); // back-fill","handlingStrategy":"validation","validationCode":"// skipBytesToWrite does NOT auto-resize; ensure capacity first\n// Trigger an auto-resize by writing a placeholder, or size the serializer generously\nif (out.length() + numBytes > /* known capacity */ Integer.MAX_VALUE) {\n    throw new EOFException(\"Not enough buffer to skip \" + numBytes + \" bytes\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember skipBytesToWrite never resizes; only write() does.","Reserve length-prefix slots before writing content so position stays in capacity.","Size the DataOutputSerializer generously for the expected record, or use write() to auto-grow."],"tags":["serialization","bounds-check","buffer-overflow"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}