From c08ec615d26508c14c44680ffe649d46be6de8c5 Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Tue, 11 Oct 2011 16:12:19 -0700 Subject: [PATCH] Bug 5385279: IOOB in createMisspelledSuggestionSpan Race condition: when spell check result come back, the spell check span may no longer be in the text, although it should have been removed by removeSpellCheckSpan. This is possible because onGetSuggestions is called from an other thread and it can see the text in an inconsistent state where the span may have been removed from the text, but the listener that calls removeSpellCheckSpan has not yet been called. As a result, onGetSuggestions still lists the span but getSpanStart returns -1. Change-Id: Ia40f7ed2b46fc94888fce5a6b209fb0d0d529bbe --- core/java/android/widget/SpellChecker.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/java/android/widget/SpellChecker.java b/core/java/android/widget/SpellChecker.java index 510e2d4cb488e..84d937ef12de4 100644 --- a/core/java/android/widget/SpellChecker.java +++ b/core/java/android/widget/SpellChecker.java @@ -239,6 +239,7 @@ public class SpellChecker implements SpellCheckerSessionListener { SuggestionsInfo suggestionsInfo, SpellCheckSpan spellCheckSpan) { final int start = editable.getSpanStart(spellCheckSpan); final int end = editable.getSpanEnd(spellCheckSpan); + if (start < 0 || end < 0) return; // span was removed in the meantime // Other suggestion spans may exist on that region, with identical suggestions, filter // them out to avoid duplicates. First, filter suggestion spans on that exact region.