aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-10-22 08:13:56 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-10-22 08:13:56 -0700
commit85781e88469c2b65d205ec4265f1991ac86ded5b (patch)
treee471de8480341446ce057c9fe11ce978917e5fae /java/src
parent74f2e69b9472e4ded9a3cc76f673e9504ad16b48 (diff)
parent42de819ae8d7e276af3299a4572788f8996a6e83 (diff)
downloadlatinime-85781e88469c2b65d205ec4265f1991ac86ded5b.tar.gz
latinime-85781e88469c2b65d205ec4265f1991ac86ded5b.tar.xz
latinime-85781e88469c2b65d205ec4265f1991ac86ded5b.zip
am 42de819a: am 1875860d: Stopgap solution for a crash.
* commit '42de819ae8d7e276af3299a4572788f8996a6e83': Stopgap solution for a crash.
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index e43cab5ca..c212f9c81 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -294,7 +294,14 @@ public final class RichInputConnection {
// the text field, then we can return the cached version right away.
if (cachedLength >= n || cachedLength >= mExpectedCursorPosition) {
final StringBuilder s = new StringBuilder(mCommittedTextBeforeComposingText);
- s.append(mComposingText);
+ // We call #toString() here to create a temporary object.
+ // In some situations, this method is called on a worker thread, and it's possible
+ // the main thread touches the contents of mComposingText while this worker thread
+ // is suspended, because mComposingText is a StringBuilder. This may lead to crashes,
+ // so we call #toString() on it. That will result in the return value being strictly
+ // speaking wrong, but since this is used for basing bigram probability off, and
+ // it's only going to matter for one getSuggestions call, it's fine in the practice.
+ s.append(mComposingText.toString());
if (s.length() > n) {
s.delete(0, s.length() - n);
}