diff options
author | 2013-10-22 11:04:39 +0000 | |
---|---|---|
committer | 2013-10-22 11:04:39 +0000 | |
commit | 787fd368c4069198111c20cdab2fe3367250c441 (patch) | |
tree | f6bc1b79e1fdc8b7b9fb84ee2f432f0877d8ee6d /java/src/com/android/inputmethod/latin/RichInputConnection.java | |
parent | 5781d176394e0a058a4029f7a38f0359200e771a (diff) | |
parent | 729abe6332a6f169e4d3df06792e67415a46ff6c (diff) | |
download | latinime-787fd368c4069198111c20cdab2fe3367250c441.tar.gz latinime-787fd368c4069198111c20cdab2fe3367250c441.tar.xz latinime-787fd368c4069198111c20cdab2fe3367250c441.zip |
Merge "Stopgap solution for a crash."
Diffstat (limited to 'java/src/com/android/inputmethod/latin/RichInputConnection.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/RichInputConnection.java | 9 |
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); } |