am 0b327101: Merge "Fix possible NPE"

* commit '0b3271010fe6e438d57a5d4504e021e001bb9f5e':
  Fix possible NPE
This commit is contained in:
Satoshi Kataoka 2013-03-25 20:50:48 -07:00 committed by Android Git Automerger
commit bc586fb1ff

View file

@ -156,7 +156,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private PositionalInfoForUserDictPendingAddition private PositionalInfoForUserDictPendingAddition
mPositionalInfoForUserDictPendingAddition = null; mPositionalInfoForUserDictPendingAddition = null;
private final WordComposer mWordComposer = new WordComposer(); 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 // 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; private static final int NOT_A_CURSOR_POSITION = -1;
@ -2297,8 +2297,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// expect to receive non-words. // expect to receive non-words.
if (!mSettings.getCurrent().mCorrectionEnabled) return null; if (!mSettings.getCurrent().mCorrectionEnabled) return null;
final Suggest suggest = mSuggest;
final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary; final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary;
if (userHistoryDictionary != null) { if (suggest == null || userHistoryDictionary == null) {
// Avoid concurrent issue
return null;
}
final String prevWord final String prevWord
= mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, 2); = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, 2);
final String secondWord; final String secondWord;
@ -2310,13 +2314,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// We demote unrecognized words (frequency < 0, below) by specifying them as "invalid". // 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.). // We don't add words with 0-frequency (assuming they would be profanity etc.).
final int maxFreq = AutoCorrection.getMaxFrequency( final int maxFreq = AutoCorrection.getMaxFrequency(
mSuggest.getUnigramDictionaries(), suggestion); suggest.getUnigramDictionaries(), suggestion);
if (maxFreq == 0) return null; if (maxFreq == 0) return null;
userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0); userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0);
return prevWord; return prevWord;
} }
return null;
}
/** /**
* Check if the cursor is actually at the end of a word. If so, restart suggestions on this * Check if the cursor is actually at the end of a word. If so, restart suggestions on this