From 550b3869951ae9c21644b5acb189a26f87fbd663 Mon Sep 17 00:00:00 2001 From: Edward Date: Thu, 27 Jun 2019 12:19:57 -0700 Subject: [PATCH] Update Utf8.java: more detailed exception message (#5421) Provide more detailed exception message for malformed 2 byte utf8 character --- java/com/google/flatbuffers/Utf8.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/java/com/google/flatbuffers/Utf8.java b/java/com/google/flatbuffers/Utf8.java index a2640637e..efb6811f8 100644 --- a/java/com/google/flatbuffers/Utf8.java +++ b/java/com/google/flatbuffers/Utf8.java @@ -110,9 +110,11 @@ public abstract class Utf8 { throws IllegalArgumentException { // Simultaneously checks for illegal trailing-byte in leading position (<= '11000000') and // overlong 2-byte, '11000001'. - if (byte1 < (byte) 0xC2 - || isNotTrailingByte(byte2)) { - throw new IllegalArgumentException("Invalid UTF-8"); + if (byte1 < (byte) 0xC2) { + throw new IllegalArgumentException("Invalid UTF-8: Illegal leading byte in 2 bytes utf"); + } + if (isNotTrailingByte(byte2)) { + throw new IllegalArgumentException("Invalid UTF-8: Illegal trailing byte in 2 bytes utf"); } resultArr[resultPos] = (char) (((byte1 & 0x1F) << 6) | trailingByteValue(byte2)); }