aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/WordComposer.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-06-02 17:47:40 +0900
committerJean Chalard <jchalard@google.com>2014-06-02 18:21:50 +0900
commitd660f3bec990851090e3adb98de236e02323011e (patch)
tree6a60fbbe83d21aa7e6c5dae2a69599c3b64b073a /java/src/com/android/inputmethod/latin/WordComposer.java
parentfa9b9578d44748de512c947651010e703c663936 (diff)
downloadlatinime-d660f3bec990851090e3adb98de236e02323011e.tar.gz
latinime-d660f3bec990851090e3adb98de236e02323011e.tar.xz
latinime-d660f3bec990851090e3adb98de236e02323011e.zip
Fix an IOOB exception
Bug: 14602663 Change-Id: Ie2060931df911b44230d5a5ba268f687cbdd0dc8
Diffstat (limited to 'java/src/com/android/inputmethod/latin/WordComposer.java')
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 864942d04..7a50d1a9d 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -145,9 +145,12 @@ public final class WordComposer {
*/
public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(
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
- final int lastIndex = mTypedWordCache.length()
- - StringUtils.getTrailingSingleQuotesCount(mTypedWordCache);
+ final int lastIndex = typedWord.length()
+ - StringUtils.getTrailingSingleQuotesCount(typedWord);
if (lastIndex <= 0) {
// The string is empty or contains only single quotes.
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
// 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) {
return -1;
}
- return StringUtils.copyCodePointsAndReturnCodePointCount(destination, mTypedWordCache, 0,
+ return StringUtils.copyCodePointsAndReturnCodePointCount(destination, typedWord, 0,
lastIndex, true /* downCase */);
}