{"record":{"id":"0ea178a1d77bd6cf","repo":"apache/flink","slug":"offset-d-length-d-size-d","errorCode":null,"errorMessage":"offset: %d, length: %d, size: %d","messagePattern":"offset: (.+?), length: (.+?), size: (.+?)","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java","lineNumber":127,"sourceCode":"        write(b, 0, b.length);\n    }\n\n    @Override\n    public void write(byte[] b, int off, int len) throws IOException {\n        if (len < 0 || off > b.length - len) {\n            throw new ArrayIndexOutOfBoundsException();\n        }\n        if (this.position > this.buffer.length - len) {\n            resize(len);\n        }\n        System.arraycopy(b, off, this.buffer, this.position, len);\n        this.position += len;\n    }\n\n    @Override\n    public void write(MemorySegment segment, int off, int len) throws IOException {\n        if (len < 0 || off < 0 || off > segment.size() - len) {\n            throw new IndexOutOfBoundsException(\n                    String.format(\"offset: %d, length: %d, size: %d\", off, len, segment.size()));\n        }\n        if (this.position > this.buffer.length - len) {\n            resize(len);\n        }\n        segment.get(off, this.buffer, this.position, len);\n        this.position += len;\n    }\n\n    @Override\n    public void writeBoolean(boolean v) throws IOException {\n        write(v ? 1 : 0);\n    }\n\n    @Override\n    public void writeByte(int v) throws IOException {\n        write(v);\n    }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java#L109-L145","documentation":"Thrown by DataOutputSerializer.write(MemorySegment segment, int off, int len) when the offset/length into the MemorySegment are out of bounds: len<0, off<0, or off > segment.size()-len. The message reports the offending offset, length, and segment size for diagnosis.","triggerScenarios":"Calling write(segment, off, len) with off<0, len<0, or off+len exceeding segment.size().","commonSituations":"Incorrect segment offset arithmetic when copying a region; reading past the end of a MemorySegment; a length derived from a record size that exceeds the segment.","solutions":["Validate off>=0, len>=0, and off+len<=segment.size() before writing.","Use segment.size() to clamp the read region.","Log segment.size() alongside off/len when the precondition fails to catch off-by-one region math."],"exampleFix":"// before\nout.write(segment, regionOffset, regionLen);\n\n// after\nif (regionOffset < 0 || regionLen < 0 || regionOffset + regionLen > segment.size()) {\n    throw new IndexOutOfBoundsException(\"bad segment region\");\n}\nout.write(segment, regionOffset, regionLen);","handlingStrategy":"validation","validationCode":"if (off < 0 || len < 0 || off + len > segment.size()) {\n    throw new IndexOutOfBoundsException(\n        String.format(\"bad segment region: off=%d len=%d size=%d\", off, len, segment.size()));\n}\nout.write(segment, off, len);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always compute region bounds against segment.size(), not a cached/stale size.","Use off+len as a single precondition rather than separate off and len checks.","Log segment.size() alongside off/len when bounds checks fail to catch off-by-one region math."],"tags":["serialization","memory-segment","bounds-check","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}