aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2013-03-27 21:59:44 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-03-27 21:59:44 -0700
commitdd8ca1f821c4f64f561e1d1badcfa5deb13de96d (patch)
tree32cd4d6c9c7a3fbef83ab91386998b6d9a87c6eb /java/src
parent56b1bd866a97b4662401ff98c287c56f4f26432a (diff)
parentbc586fb1ff553bc640676b348b3b24ee2626bf42 (diff)
downloadlatinime-dd8ca1f821c4f64f561e1d1badcfa5deb13de96d.tar.gz
latinime-dd8ca1f821c4f64f561e1d1badcfa5deb13de96d.tar.xz
latinime-dd8ca1f821c4f64f561e1d1badcfa5deb13de96d.zip
am bc586fb1: am 0b327101: Merge "Fix possible NPE"
* commit 'bc586fb1ff553bc640676b348b3b24ee2626bf42': Fix possible NPE
Diffstat (limited to 'java/src')
-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;
}
/**