Update Utf8.java: more detailed exception message (#5421)

Provide more detailed exception message for malformed 2 byte utf8 character
This commit is contained in:
Edward 2019-06-27 12:19:57 -07:00 committed by Wouter van Oortmerssen
parent 5479adc80f
commit 550b386995
1 changed files with 5 additions and 3 deletions

View File

@ -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));
}