apache/flink · error · UTFDataFormatException

malformed input: partial character at end

Error message

malformed input: partial character at end

What it means

Thrown as a UTFDataFormatException by AbstractPagedInputView's modified-UTF-8 reader when a two-byte sequence (lead byte 0b110xxxxx) is started but the stream ends before the continuation byte can be read (count exceeds utflen). This means a multi-byte UTF-8 character was split at the boundary of the declared UTF length, indicating truncation or corruption of the string payload.

Source

Thrown at flink-core/src/main/java/org/apache/flink/core/memory/AbstractPagedInputView.java:462

            switch (c >> 4) {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                    /* 0xxxxxxx */
                    count++;
                    chararr[chararrCount++] = (char) c;
                    break;
                case 12:
                case 13:
                    /* 110x xxxx 10xx xxxx */
                    count += 2;
                    if (count > utflen) {
                        throw new UTFDataFormatException(
                                "malformed input: partial character at end");
                    }
                    char2 = (int) bytearr[count - 1];
                    if ((char2 & 0xC0) != 0x80) {
                        throw new UTFDataFormatException("malformed input around byte " + count);
                    }
                    chararr[chararrCount++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
                    break;
                case 14:
                    /* 1110 xxxx 10xx xxxx 10xx xxxx */
                    count += 3;
                    if (count > utflen) {
                        throw new UTFDataFormatException(
                                "malformed input: partial character at end");
                    }
                    char2 = (int) bytearr[count - 2];
                    char3 = (int) bytearr[count - 1];
                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Verify the string was written with the matching writeUTF and the length prefix is correct.
  2. Ensure the underlying data is not truncated — check total byte count against expected.
  3. Avoid manual construction of modified-UTF-8 byte arrays; use the provided writeUTF/readUTF pair.
  4. If data corruption is systemic, regenerate the checkpoint/savepoint from a known-good source.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    String s = inputView.readUTF();
} catch (UTFDataFormatException e) {
    // truncated multi-byte character; verify data integrity
}

Prevention

When it happens

Trigger: Reading a UTF string via readUTF() where the declared utflen is too short to contain the full multi-byte character at the end; truncation of the byte array mid-character; corruption of the length prefix.

Common situations: Truncated string data in serialized records; inconsistent write/read of UTF length prefixes; segment boundary splits corrupting the character.

Understand the failure class

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/ef3af0ce19c498a4. Report an issue: GitHub.