tinkoff-mobile-tech / decoro

Android library designed for automatic formatting of text input by custom rules
Apache License 2.0
391 stars 31 forks source link

On prod: java.lang.StringIndexOutOfBoundsException #56

Open ilyaklyukin opened 4 years ago

ilyaklyukin commented 4 years ago

implementation 'ru.tinkoff.decoro:decoro:1.5.0'

We see multiple crashes in Firebase crashlytics:

Fatal Exception: java.lang.StringIndexOutOfBoundsException: length=0; index=8 at java.lang.String.substring(String.java:2060) at ru.tinkoff.decoro.watchers.FormatWatcher.afterTextChanged(FormatWatcher.java:255) at android.widget.TextView.sendAfterTextChanged(TextView.java:11664) at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:14910) at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1277) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:577) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:507) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:37) at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:849) at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:618) at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:393) at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:89) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:7814) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

MairwunNx commented 3 years ago

@ilyaklyukin you must write unit tests (with attachments passed values to afterTextChanged) for better investigating this issue.

Without it investigating this issue impossible.

elephant16 commented 2 years ago

The same issue. Appears on some devices if inputType in EditText is set. About 64 out of 2000 users had this error.

This is very similar to the following problem, see the link https://github.com/RedMadRobot/input-mask-android#inputmask-vs-androidinputtype-and-indexoutofboundsexception