Fix an IOOB exception

Bug: 17316001
Change-Id: Iaa2cfd30ebbe0d49e10a5c3a30336e06817d0a8b
main
Jean Chalard 2014-08-29 13:18:23 +09:00
parent f2eadbb497
commit 4e28a6a844
2 changed files with 11 additions and 1 deletions

View File

@ -429,7 +429,7 @@ public class SuggestedWords {
*/
@UsedForTesting
public SuggestedWordInfo getTypedWordInfoOrNull() {
if (this == EMPTY) {
if (SuggestedWords.INDEX_OF_TYPED_WORD >= size()) {
return null;
}
final SuggestedWordInfo info = getInfo(SuggestedWords.INDEX_OF_TYPED_WORD);

View File

@ -148,5 +148,15 @@ public class SuggestedWordsTests extends AndroidTestCase {
// Make sure getTypedWordInfoOrNull() returns null.
assertNull(SuggestedWords.EMPTY.getTypedWordInfoOrNull());
final SuggestedWords emptySuggestedWords = new SuggestedWords(
new ArrayList<SuggestedWordInfo>(), null /* rawSuggestions */,
false /* typedWordValid */,
false /* willAutoCorrect */,
false /* isObsoleteSuggestions */,
SuggestedWords.INPUT_STYLE_NONE);
assertNull(emptySuggestedWords.getTypedWordInfoOrNull());
assertNull(SuggestedWords.EMPTY.getTypedWordInfoOrNull());
}
}