I get this ACRA report from an unknown source using an app I posted to Google Play:
java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 1
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1090)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:665)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:658)
at android.text.Selection.setSelection(Selection.java:76)
at android.text.Selection.setSelection(Selection.java:87)
at android.widget.EditText.setSelection(EditText.java:98)
at android.widget.EditText.performAccessibilityActionInternal(EditText.java:138)
at android.view.View.performAccessibilityAction(View.java:8889)
at android.view.AccessibilityInteractionController.performAccessibilityActionUiThread(AccessibilityInteractionController.java:668)
at android.view.AccessibilityInteractionController.-wrap6(AccessibilityInteractionController.java)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1194)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5421)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
None of the stack frames indicate any of my code (it's all Android internal code) so I don't know what it could be. It is not like my app is calling something with parameters saying to access characters 4...4 of a 1 character string. So unfortunately answers saying that I am accessing characters beyond the end of the string (or equivalent array elements) aren't of much help. Somehow it seems something internal to Android, without my app calling anything, is doing this. And I don't really know what the user is doing to trigger it, possibly doing some funky string select thing in a text entry box. Thanks for the help.
Should have said this is Android SDK 23.
Digging through that Android code, EditText.java line 138:
case AccessibilityNodeInfo.ACTION_SET_TEXT: {
CharSequence text = (arguments != null) ? arguments.getCharSequence(
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE) : null;
setText(text);
// must retrieve possibly modified text
if (text != null && text.length() > 0) {
setSelection(text.length()); // 138: il puque ici
}
return true;
}
So on line 138 has the bad setSelection() call using text.length() as its argument to set the cursor at the end of the text. So how can text.length() be 4 if the length of the text is 1 you ask? Well TextView.setText() that is called a couple lines above that modifies the text under certain circumstances (as yet unknown to me), apparently in this case shortening it from 4 characters to 1.
It turns out this is an Android bug. https://android.googlesource.com/platform/frameworks/base/+/6dde7e7
The only thing I can find that I think are text filters is setting input type to InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL then trying to do setText (Double.toString (Double.NaN)) but it happily displays NaN in the text box without crashing using Sdk 23 in the emulator. I know the filter is in place because Android shows the numeric keypad for entering data into the text box.
Does anyone know how to get the filter to actually do something?