{"record":{"id":"ebf76ffa26f4790e","repo":"apache/flink","slug":"encoded-string-reached-maximum-length-utflen","errorCode":null,"errorMessage":"Encoded string reached maximum length: {utflen}","messagePattern":"Encoded string reached maximum length: (.+?)","errorType":"exception","errorClass":"UTFDataFormatException","httpStatus":null,"severity":"critical","filePath":"flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java","lineNumber":276,"sourceCode":"    /**\n     * Similar to {@link #writeUTF(String)}. The size is only limited by the maximum java array size\n     * of the buffer.\n     *\n     * @param str the string value to be written.\n     * @throws IOException if an I/O error occurs.\n     */\n    public void writeLongUTF(String str) throws IOException {\n        int strlen = str.length();\n        long utflen = 0;\n        int c;\n\n        /* use charAt instead of copying String to char array */\n        for (int i = 0; i < strlen; i++) {\n            c = str.charAt(i);\n            utflen += getUTFBytesSize(c);\n\n            if (utflen > Integer.MAX_VALUE) {\n                throw new UTFDataFormatException(\n                        \"Encoded string reached maximum length: \" + utflen);\n            }\n        }\n\n        if (utflen > Integer.MAX_VALUE - 4) {\n            throw new UTFDataFormatException(\"Encoded string is too long: \" + utflen);\n        } else if (this.position > this.buffer.length - utflen - 2) {\n            resize((int) utflen + 4);\n        }\n\n        writeInt((int) utflen);\n\n        writeUTFBytes(str);\n    }\n\n    private void writeUTFBytes(String str) {\n        int strlen = str.length();\n        int c;","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java#L258-L294","documentation":"Thrown by DataOutputSerializer.writeLongUTF(String) during the per-character byte-size accumulation when the running total (a long) exceeds Integer.MAX_VALUE. Because the backing buffer is a Java array (int-indexed), the encoded length cannot exceed ~2GB, so writeLongUTF aborts as soon as the running total crosses that threshold.","triggerScenarios":"Calling writeLongUTF(str) on a string whose modified-UTF-8 encoding would exceed Integer.MAX_VALUE (~2.1GB) bytes.","commonSituations":"Pathologically large in-memory strings; concatenating unbounded user/audit content into a single string; a memory-resident blob mistakenly treated as a String.","solutions":["Avoid holding such large payloads as a single String; serialize as a byte[] or stream instead.","Enforce a maximum input string length at the API boundary before serialization.","If genuinely large binary data is needed, write it as raw bytes with an int length prefix rather than a modified-UTF-8 String."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"static long modifiedUtf8LenLong(String s) {\n    long n = 0;\n    for (int i = 0; i < s.length(); i++) {\n        int c = s.charAt(i);\n        n += (c >= 0x0001 && c <= 0x007F) ? 1 : (c > 0x07FF ? 3 : 2);\n    }\n    return n;\n}\n// if (modifiedUtf8LenLong(str) > Integer.MAX_VALUE) reject or serialize as raw bytes","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not hold payloads larger than ~2GB as a single String.","Enforce a maximum input string size at the application boundary.","Serialize large binary payloads as byte[] with an int length prefix, not as modified-UTF-8."],"tags":["serialization","utf-8","string","size-limit","memory"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}