diff options
author | 2011-07-19 18:59:12 +0900 | |
---|---|---|
committer | 2011-07-19 19:25:48 +0900 | |
commit | 40f7efc172928bdd6048e91421a766abe5b22996 (patch) | |
tree | e6401b359396828742fbabcf5e974dd93dfe9789 /java/src/com/android/inputmethod/latin/LatinIME.java | |
parent | 44861474fbea784f12fe86bc56d30d5d9be4ad81 (diff) | |
download | latinime-40f7efc172928bdd6048e91421a766abe5b22996.tar.gz latinime-40f7efc172928bdd6048e91421a766abe5b22996.tar.xz latinime-40f7efc172928bdd6048e91421a766abe5b22996.zip |
Fix an NPE related to absent InputConnection
Bug: 5035577
Change-Id: I1a11fc475d4a0f692636000d0b0f40bc35427867
Diffstat (limited to '')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b7a795221..95cae6ed5 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1514,9 +1514,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final WordComposer wordComposer = mWordComposer; // TODO: May need a better way of retrieving previous word - CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(), - mSettingsValues.mWordSeparators); - SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( + final InputConnection ic = getCurrentInputConnection(); + final CharSequence prevWord; + if (null == ic) { + prevWord = null; + } else { + prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators); + } + // getSuggestedWordBuilder handles gracefully a null value of prevWord + final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( mKeyboardSwitcher.getKeyboardView(), wordComposer, prevWord); boolean autoCorrectionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection(); @@ -1788,10 +1794,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // We don't want to register as bigrams words separated by a separator. // For example "I will, and you too" : we don't want the pair ("will" "and") to be // a bigram. - CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(), - mSettingsValues.mWordSeparators); - if (!TextUtils.isEmpty(prevWord)) { - mUserBigramDictionary.addBigrams(prevWord.toString(), suggestion.toString()); + final InputConnection ic = getCurrentInputConnection(); + if (null != ic) { + final CharSequence prevWord = + EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators); + if (!TextUtils.isEmpty(prevWord)) { + mUserBigramDictionary.addBigrams(prevWord.toString(), suggestion.toString()); + } } } } |