Fix a bug in SpellCheckerService.

Previously, the returned value of WordIterator#following is used without
checking, which will cause fatal error when it's WordIterator.DONE.

Fix: 184915852
Test: atest CtsInputMethodTestCases:SpellCheckerTest
Change-Id: I37418bb36bc49e7dfa729ffb7209a6f383b611dd
This commit is contained in:
Qi Wang
2021-04-16 12:48:42 +08:00
parent 1233b55e1e
commit 2616a431e7

View File

@@ -421,7 +421,8 @@ public abstract class SpellCheckerService extends Service {
final ArrayList<SentenceWordItem> wordItems = new ArrayList<SentenceWordItem>();
wordIterator.setCharSequence(originalText, 0, originalText.length());
int wordEnd = wordIterator.following(start);
int wordStart = wordIterator.getBeginning(wordEnd);
int wordStart = wordEnd == BreakIterator.DONE ? BreakIterator.DONE
: wordIterator.getBeginning(wordEnd);
if (DBG) {
Log.d(TAG, "iterator: break: ---- 1st word start = " + wordStart + ", end = "
+ wordEnd + "\n" + originalText);