Avoid crashes

This commit is contained in:
Andrea Cavalli 2022-01-22 17:46:20 +01:00
parent 82bc60d510
commit b1b191a6e7

View File

@ -79,8 +79,12 @@ public class MessageEntity implements BotApiObject {
public void computeText(String message) { public void computeText(String message) {
if (message != null) { if (message != null) {
byte[] bytes = message.getBytes(StandardCharsets.UTF_16LE); byte[] bytes = message.getBytes(StandardCharsets.UTF_16LE);
if (bytes.length >= offset && offset >= 0 && length >= 0) {
text = new String(Arrays.copyOfRange(bytes, offset, offset + length), text = new String(Arrays.copyOfRange(bytes, offset, offset + length),
StandardCharsets.UTF_16LE); StandardCharsets.UTF_16LE);
} else {
text = "";
}
} }
} }
} }