{"record":{"id":"815599b52ed736ea","repo":"apache/iceberg","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":"error","filePath":"flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/util/SerializerHelper.java","lineNumber":65,"sourceCode":"   *\n   * <p>See * <a href=\"https://issues.apache.org/jira/browse/FLINK-34228\">FLINK-34228</a> * <a\n   * href=\"https://github.com/apache/flink/pull/24191\">https://github.com/apache/flink/pull/24191</a>\n   *\n   * @param out the output stream to write the string to.\n   * @param str the string value to be written.\n   */\n  public static void writeLongUTF(DataOutputView out, String str) throws IOException {\n    int strlen = str.length();\n    long utflen = 0;\n    int ch;\n\n    /* use charAt instead of copying String to char array */\n    for (int i = 0; i < strlen; i++) {\n      ch = str.charAt(i);\n      utflen += getUTFBytesSize(ch);\n\n      if (utflen > Integer.MAX_VALUE) {\n        throw new UTFDataFormatException(\"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    }\n\n    out.writeInt((int) utflen);\n    writeUTFBytes(out, str, (int) utflen);\n  }\n\n  /**\n   * Similar to {@link DataInputDeserializer#readUTF()}. Except this supports larger payloads which\n   * is up to max integer value.\n   *\n   * <p>Note: This method can be removed when the method which does similar thing within the {@link\n   * DataOutputSerializer} already which does the same thing, so use that one instead once that is\n   * released on Flink version 1.20.","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/util/SerializerHelper.java#L47-L83","documentation":"SerializerHelper.writeLongUTF encodes a string as modified UTF-8 and tracks the running byte length. If the encoded length would exceed Integer.MAX_VALUE during the per-character accounting loop, it throws UTFDataFormatException immediately, since the length cannot be represented. This is a hard limit of the DataOutput-style encoding used for Flink serializer compatibility.","triggerScenarios":"Calling writeLongUTF with a string whose UTF-8 encoding exceeds 2^31-1 bytes (~2GB).","commonSituations":"Serializing extremely large strings such as huge JSON payloads or binary data smuggled through String columns across Flink checkpoints/state.","solutions":["Reduce the string size below Integer.MAX_VALUE encoded bytes before writing","Split the payload into chunks and write multiple strings","Use a different transport (e.g. binary byte arrays or external storage) for >2GB payloads"],"exampleFix":"// before\nhelper.writeLongUTF(hugePayload); // throws if > Integer.MAX_VALUE bytes\n// after\nif (getUTFBytesSize(hugePayload) < Integer.MAX_VALUE) {\n  helper.writeLongUTF(hugePayload);\n} else {\n  writeChunked(hugePayload);\n}","handlingStrategy":"validation","validationCode":"int size = SerializerHelper.getUTFBytesSize(str);\nif (size >= Integer.MAX_VALUE) {\n  throw new IllegalArgumentException(\"string exceeds encoder limit: \" + size);\n}\nhelper.writeLongUTF(str);","typeGuard":null,"tryCatchPattern":"try {\n  helper.writeLongUTF(str);\n} catch (UTFDataFormatException e) {\n  // fall back to chunked storage or external reference\n  writeExternalRef(str);\n}","preventionTips":["Cap serialized string sizes well below 2GB","Chunk large payloads before writing","Store large blobs outside serializer state"],"tags":["flink","serialization","utf","limit"],"backgroundTag":"value-out-of-range","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}