aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2013-03-26 03:49:05 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-03-26 03:49:06 +0000
commit0b3271010fe6e438d57a5d4504e021e001bb9f5e (patch)
tree810c397e793f3b841c1116e1cbf81ea551ea79b0 /java/src/com/android/inputmethod
parentd17b69ec000adc02f057fa69055411fd5438885f (diff)
parenta17dccbfc624c991ca054a5436519e74e0a60b54 (diff)
downloadlatinime-0b3271010fe6e438d57a5d4504e021e001bb9f5e.tar.gz
latinime-0b3271010fe6e438d57a5d4504e021e001bb9f5e.tar.xz
latinime-0b3271010fe6e438d57a5d4504e021e001bb9f5e.zip
Merge "Fix possible NPE"
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java40
1 files changed, 21 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ea7ee6d5b..7bd09811c 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -156,7 +156,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private PositionalInfoForUserDictPendingAddition
mPositionalInfoForUserDictPendingAddition = null;
private final WordComposer mWordComposer = new WordComposer();
- private RichInputConnection mConnection = new RichInputConnection(this);
+ private final RichInputConnection mConnection = new RichInputConnection(this);
// Keep track of the last selection range to decide if we need to show word alternatives
private static final int NOT_A_CURSOR_POSITION = -1;
@@ -2297,25 +2297,27 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// expect to receive non-words.
if (!mSettings.getCurrent().mCorrectionEnabled) return null;
+ final Suggest suggest = mSuggest;
final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary;
- if (userHistoryDictionary != null) {
- final String prevWord
- = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, 2);
- final String secondWord;
- if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
- secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
- } else {
- secondWord = suggestion;
- }
- // We demote unrecognized words (frequency < 0, below) by specifying them as "invalid".
- // We don't add words with 0-frequency (assuming they would be profanity etc.).
- final int maxFreq = AutoCorrection.getMaxFrequency(
- mSuggest.getUnigramDictionaries(), suggestion);
- if (maxFreq == 0) return null;
- userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0);
- return prevWord;
- }
- return null;
+ if (suggest == null || userHistoryDictionary == null) {
+ // Avoid concurrent issue
+ return null;
+ }
+ final String prevWord
+ = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, 2);
+ final String secondWord;
+ if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
+ secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
+ } else {
+ secondWord = suggestion;
+ }
+ // We demote unrecognized words (frequency < 0, below) by specifying them as "invalid".
+ // We don't add words with 0-frequency (assuming they would be profanity etc.).
+ final int maxFreq = AutoCorrection.getMaxFrequency(
+ suggest.getUnigramDictionaries(), suggestion);
+ if (maxFreq == 0) return null;
+ userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0);
+ return prevWord;
}
/**