Source:
<code><START> private static int getCodePointAtSafe(Slice utf8, int position) <END> { byte firstByte = utf8.getByte(position); int length = lengthOfCodePointFromStartByteSafe(firstByte); if (length < 0) { return length; } if (position + length > utf8.length()) { return -(utf8.length() - position); } if (length == 1) { return firstByte; } byte secondByte = utf8.getByte(position + 1); if (!isContinuationByte(secondByte)) { return -1; } if (length == 2) { return ((firstByte & 0b0001_1111) << 6) | (secondByte & 0b0011_1111); } byte thirdByte = utf8.getByteUnchecked(position + 2); if (!isContinuationByte(thirdByte)) { return -2; } if (length == 3) { return ((firstByte & 0b0000_1111) << 12) | ((secondByte & 0b0011_1111) << 6) | (thirdByte & 0b0011_1111); } byte forthByte = utf8.getByteUnchecked(position + 3); if (!isContinuationByte(forthByte)) { return -3; } if (length == 4) { int codePoint = ((firstByte & 0b0000_0111) << 18) | ((secondByte & 0b0011_1111) << 12) | ((thirdByte & 0b0011_1111) << 6) | (forthByte & 0b0011_1111); if (codePoint < 0x11_0000) { return codePoint; } return -4; } byte fifthByte = utf8.getByteUnchecked(position + 4); if (!isContinuationByte(fifthByte)) { return -4; } if (length == 5) { return -5; } byte sixthByte = utf8.getByteUnchecked(position + 5); if (!isContinuationByte(sixthByte)) { return -5; } if (length == 6) { return -6; } return -1; }</code><technical_language>This function getByte for 1st 2nd byte, getByteUnchecked for 3rd byte onwards. This inconsistency appears a bug. - If getByteUnchecked is 1st byte, this function named "unchecked". - Otherwise, this function need do a bound check reading 2nd-nth byte getByteUnchecked. If bound check is done, this function need named "unchecked"</technical_language>

Target:
private static int getCodePointAtSafe(Slice utf8, int position) { byte firstByte = utf8.getByte(position); int length = lengthOfCodePointFromStartByteSafe(firstByte); if (length < 0) { return length; } if (length == 1) { return firstByte; } if (position + 1 >= utf8.length()) { return -1; } byte secondByte = utf8.getByteUnchecked(position + 1); if (!isContinuationByte(secondByte)) { return -1; } if (length == 2) { return ((firstByte & 0b0001_1111) << 6) | (secondByte & 0b0011_1111); } if (position + 2 >= utf8.length()) { return -2; } byte thirdByte = utf8.getByteUnchecked(position + 2); if (!isContinuationByte(thirdByte)) { return -2; } if (length == 3) { int codePoint = ((firstByte & 0b0000_1111) << 12) | ((secondByte & 0b0011_1111) << 6) | (thirdByte & 0b0011_1111); if (MIN_SURROGATE <= codePoint && codePoint <= MAX_SURROGATE) { return -3; } return codePoint; } if (position + 3 >= utf8.length()) { return -3; } byte forthByte = utf8.getByteUnchecked(position + 3); if (!isContinuationByte(forthByte)) { return -3; } if (length == 4) { int codePoint = ((firstByte & 0b0000_0111) << 18) | ((secondByte & 0b0011_1111) << 12) | ((thirdByte & 0b0011_1111) << 6) | (forthByte & 0b0011_1111); if (codePoint < 0x11_0000) { return codePoint; } return -4; } if (position + 4 >= utf8.length()) { return -4; } byte fifthByte = utf8.getByteUnchecked(position + 4); if (!isContinuationByte(fifthByte)) { return -4; } if (length == 5) { return -5; } if (position + 5 >= utf8.length()) { return -5; } byte sixthByte = utf8.getByteUnchecked(position + 5); if (!isContinuationByte(sixthByte)) { return -5; } if (length == 6) { return -6; } return -1; }