avoid StringIndexOutOfBoundsException when initializing stringbuilder from other stringbuilder

This commit is contained in:
Helium314 2025-06-15 17:43:06 +02:00
parent ef3191a2eb
commit 24a2eddc1f

View file

@ -439,7 +439,7 @@ public final class RichInputConnection implements PrivateCommandPerformer {
// test for this explicitly) // test for this explicitly)
if (INVALID_CURSOR_POSITION != mExpectedSelStart if (INVALID_CURSOR_POSITION != mExpectedSelStart
&& (cachedLength >= n || cachedLength >= mExpectedSelStart)) { && (cachedLength >= n || cachedLength >= mExpectedSelStart)) {
final StringBuilder s = new StringBuilder(mCommittedTextBeforeComposingText); final StringBuilder s = new StringBuilder(mCommittedTextBeforeComposingText.toString());
// We call #toString() here to create a temporary object. // We call #toString() here to create a temporary object.
// In some situations, this method is called on a worker thread, and it's possible // 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 // the main thread touches the contents of mComposingText while this worker thread