splitwise / TokenAutoComplete

Gmail style MultiAutoCompleteTextView for Android
Apache License 2.0
1.3k stars 384 forks source link

API 31/32 Crashes on comma completion after shouldIgnoreToken triggers #444

Open phazei opened 1 year ago

phazei commented 1 year ago

This hasn't crashed on the emulator for API 28 and 31. This crashes on my Samsung Galaxy S10e running Android 12 One UI 4.1. Very simple tag input, strings only.

    override fun shouldIgnoreToken(token: String): Boolean {
        return objects.contains(token)
    }
Process: com.phazei.dynamicgptchat, PID: 16443
        java.lang.ArrayIndexOutOfBoundsException: src.length=10 srcPos=10 dst.length=10 dstPos=2 length=3
        at java.lang.System.arraycopy(Native Method)
        at android.text.SpannableStringBuilder.moveGapTo(SpannableStringBuilder.java:180)
        at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:387)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:560)
        at androidx.emoji2.text.SpannableBuilder.replace(SpannableBuilder.java:315)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:518)
        at androidx.emoji2.text.SpannableBuilder.replace(SpannableBuilder.java:305)
        at androidx.emoji2.text.SpannableBuilder.replace(SpannableBuilder.java:49)
        at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:945)
        at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:219)
        at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:204)
        at android.view.inputmethod.InputConnectionWrapper.commitText(InputConnectionWrapper.java:192)
        at android.view.inputmethod.InputConnectionWrapper.commitText(InputConnectionWrapper.java:192)
        at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:561)
        at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:118)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8751)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Edit: After more testing, I found that it does happen in the emulator too, on 31 and 32 (28 works). It specifically only crashes when I use the soft keyboard, on either real phone or emulator, to submit the ",". So it's a directly related issue to the other ticket I closed. Here in v4 the issue was fixed for regular input, but whatever it's doing related to shouldIgnoreToken, it's still having a related issue. It does call that method just fine, it's sometime after it's called that it crashes. Works fine with keyboard ",", fails with softkeyboard "," 😔

phazei commented 1 year ago

Entered "aaa," then entered "aaa," a second time TokenCompleteTextView.kt line 839

            } else if (shouldIgnoreToken(tokenSpan.token)) {
                editable.replace(candidateRange.start, candidateRange.end, "")

Edit, never mind, thought this was something. Gets passed here then ends up in a spannable class and crashes. I'm trying to debug but I can't figure it out.