Fix an IOOB exception

Bug: 14602663
Change-Id: Ie2060931df911b44230d5a5ba268f687cbdd0dc8
This commit is contained in:
Jean Chalard 2014-06-02 17:47:40 +09:00
parent fa9b9578d4
commit d660f3bec9

View file

@ -145,9 +145,12 @@ public final class WordComposer {
*/ */
public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount( public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(
final int[] destination) { final int[] destination) {
// This method can be called on a separate thread and mTypedWordCache can change while we
// are executing this method.
final String typedWord = mTypedWordCache.toString();
// lastIndex is exclusive // lastIndex is exclusive
final int lastIndex = mTypedWordCache.length() final int lastIndex = typedWord.length()
- StringUtils.getTrailingSingleQuotesCount(mTypedWordCache); - StringUtils.getTrailingSingleQuotesCount(typedWord);
if (lastIndex <= 0) { if (lastIndex <= 0) {
// The string is empty or contains only single quotes. // The string is empty or contains only single quotes.
return 0; return 0;
@ -155,11 +158,11 @@ public final class WordComposer {
// The following function counts the number of code points in the text range which begins // The following function counts the number of code points in the text range which begins
// at index 0 and extends to the character at lastIndex. // at index 0 and extends to the character at lastIndex.
final int codePointSize = Character.codePointCount(mTypedWordCache, 0, lastIndex); final int codePointSize = Character.codePointCount(typedWord, 0, lastIndex);
if (codePointSize > destination.length) { if (codePointSize > destination.length) {
return -1; return -1;
} }
return StringUtils.copyCodePointsAndReturnCodePointCount(destination, mTypedWordCache, 0, return StringUtils.copyCodePointsAndReturnCodePointCount(destination, typedWord, 0,
lastIndex, true /* downCase */); lastIndex, true /* downCase */);
} }