Fix a NPE when sent buggy data by an application

Bug: 5072247
Change-Id: I7369877072f6bb94dff5b1bcf52c9f8dde4854b7
This commit is contained in:
Jean Chalard 2011-07-26 19:24:58 +09:00
parent 9a388f2ef3
commit e576a0d537

View file

@ -16,6 +16,7 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.text.TextUtils;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
import java.util.ArrayList; import java.util.ArrayList;
@ -105,14 +106,18 @@ public class SuggestedWords {
} }
private Builder addWord(CharSequence word, SuggestedWordInfo suggestedWordInfo) { private Builder addWord(CharSequence word, SuggestedWordInfo suggestedWordInfo) {
if (!TextUtils.isEmpty(word)) {
mWords.add(word); mWords.add(word);
// It's okay if suggestedWordInfo is null since it's checked where it's used.
mSuggestedWordInfoList.add(suggestedWordInfo); mSuggestedWordInfoList.add(suggestedWordInfo);
}
return this; return this;
} }
public Builder setApplicationSpecifiedCompletions(CompletionInfo[] infos) { public Builder setApplicationSpecifiedCompletions(CompletionInfo[] infos) {
for (CompletionInfo info : infos) for (CompletionInfo info : infos) {
addWord(info.getText()); if (null != info) addWord(info.getText());
}
return this; return this;
} }