From a294d9c4caf17af6f0d65c66d63d9bc43d48ed69 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Tue, 12 Mar 2024 11:44:33 -0500 Subject: [PATCH] Fix potential crash related to fullContext --- .../futo/inputmethod/latin/RichInputConnection.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/java/src/org/futo/inputmethod/latin/RichInputConnection.java b/java/src/org/futo/inputmethod/latin/RichInputConnection.java index b8dfba59e..d28effc34 100644 --- a/java/src/org/futo/inputmethod/latin/RichInputConnection.java +++ b/java/src/org/futo/inputmethod/latin/RichInputConnection.java @@ -686,11 +686,15 @@ public final class RichInputConnection implements PrivateCommandPerformer { NgramContext ngramContext = NgramContextUtils.getNgramContextFromNthPreviousWord( prev, spacingAndPunctuations, n); - ngramContext.fullContext = getTextBeforeCursor(4096, 0).toString(); - - if(ngramContext.fullContext.length() == 4096) { - ngramContext.fullContext = String.join(" ",ngramContext.fullContext.split(" ")).substring(ngramContext.fullContext.split(" ")[0].length()+1); + CharSequence seq = getTextBeforeCursor(4096, 0); + if(seq != null) { + ngramContext.fullContext = seq.toString(); + if (ngramContext.fullContext.length() == 4096) { + ngramContext.fullContext = String.join(" ", ngramContext.fullContext.split(" ")).substring(ngramContext.fullContext.split(" ")[0].length() + 1); + } + } else { + ngramContext.fullContext = ""; } return ngramContext;