{"record":{"id":"a461ea67fcba76b6","repo":"apache/flink","slug":"offset-len-value-len","errorCode":null,"errorMessage":"offset: {} len: {} value.len: {}","messagePattern":"offset: (.+?) len: (.+?) value\\.len: (.+?)","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/StringValue.java","lineNumber":199,"sourceCode":"     * @param offset The position to start the substring.\n     * @param len The length of the substring.\n     */\n    public void setValue(StringValue value, int offset, int len) {\n        checkNotNull(value);\n        setValue(value.value, offset, len);\n    }\n\n    /**\n     * Sets the value of the StringValue to a substring of the given string.\n     *\n     * @param value The new string value.\n     * @param offset The position to start the substring.\n     * @param len The length of the substring.\n     */\n    public void setValue(CharSequence value, int offset, int len) {\n        checkNotNull(value);\n        if (offset < 0 || len < 0 || offset > value.length() - len) {\n            throw new IndexOutOfBoundsException(\n                    \"offset: \" + offset + \" len: \" + len + \" value.len: \" + len);\n        }\n\n        ensureSize(len);\n        this.len = len;\n        for (int i = 0; i < len; i++) {\n            this.value[i] = value.charAt(offset + i);\n        }\n        this.hashCode = 0;\n    }\n\n    /**\n     * Sets the contents of this string to the contents of the given <tt>CharBuffer</tt>. The\n     * characters between the buffer's current position (inclusive) and the buffer's limit\n     * (exclusive) will be stored in this string.\n     *\n     * @param buffer The character buffer to read the characters from.\n     */","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/StringValue.java#L181-L217","documentation":"setValue(CharSequence value, int offset, int len) validates the substring range and throws IndexOutOfBoundsException on negative offset/len or when offset > value.length() - len (range past the end). Note the message has a long-standing bug: it prints 'value.len: ' + len instead of value.length(), so the reported value.len is actually the requested length — do not trust it for diagnosis.","triggerScenarios":"Calling setValue(seq, offset, len) with offset+len exceeding seq.length(), a negative offset, or a negative len; common when computing substrings from lengths derived elsewhere (e.g. parser positions).","commonSituations":"Parser/lexer code carrying offsets past the input end; off-by-one in loop bounds; reusing an offset variable after the source string changed to a shorter one.","solutions":["Validate offset >= 0 && len >= 0 && offset + len <= value.length() before the call","Prefer setValue(value.subSequence(offset, offset + len).toString()) if bounds come from untrusted computation","Remember the exception's value.len field is bogus; log value.length() yourself"],"exampleFix":"// before\nsv.setValue(text, start, width); // start+width may exceed text.length()\n\n// after\nint end = Math.min(start + width, text.length());\nsv.setValue(text, start, end - start);","handlingStrategy":"validation","validationCode":"if (offset < 0 || len < 0 || offset > value.length() - len) {\n    throw new IllegalArgumentException(\"substring [\" + offset + \",\" + (offset + len) + \") vs length \" + value.length());\n}\nsv.setValue(value, offset, len);","typeGuard":null,"tryCatchPattern":"catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException(\"Bad substring range\", e); }","preventionTips":["Clamp computed ranges with Math.min","Log value.length() yourself — the message prints len instead","Watch for stale offsets after the source string changes"],"tags":["flink","string-value","index-out-of-bounds","bounds-check"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}