am 78bb2dd9: am 3bd8eee3: am 4e28a6a8: Fix an IOOB exception

* commit '78bb2dd945a013f230396f3ce9c122a20fec21cf':
  Fix an IOOB exception
main
Jean Chalard 2014-08-29 19:19:09 +00:00 committed by Android Git Automerger
commit 2b44ba116a
2 changed files with 11 additions and 1 deletions

View File

@ -429,7 +429,7 @@ public class SuggestedWords {
*/ */
@UsedForTesting @UsedForTesting
public SuggestedWordInfo getTypedWordInfoOrNull() { public SuggestedWordInfo getTypedWordInfoOrNull() {
if (this == EMPTY) { if (SuggestedWords.INDEX_OF_TYPED_WORD >= size()) {
return null; return null;
} }
final SuggestedWordInfo info = getInfo(SuggestedWords.INDEX_OF_TYPED_WORD); 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. // Make sure getTypedWordInfoOrNull() returns null.
assertNull(SuggestedWords.EMPTY.getTypedWordInfoOrNull()); 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());
} }
} }