TWiStErRob / net.twisterrob.inventory

Magic Home Inventory https://play.google.com/store/apps/details?id=net.twisterrob.inventory
https://www.twisterrob.net/project/inventory/
20 stars 1 forks source link

Crash: IndexOutOfBoundsException in Hinter.unhighlight #364

Open TWiStErRob opened 11 months ago

TWiStErRob commented 11 months ago

Version: 12001279 (1.2.0#1279-8eca619)

Exception java.lang.IndexOutOfBoundsException:
  at android.text.SpannableStringBuilder.charAt (SpannableStringBuilder.java:126)
  at android.text.CharSequenceCharacterIterator.current (CharSequenceCharacterIterator.java:58)
  at android.text.CharSequenceCharacterIterator.setIndex (CharSequenceCharacterIterator.java:83)
  at android.icu.text.RuleBasedBreakIterator.CISetIndex32 (RuleBasedBreakIterator.java:1055)
  at android.icu.text.RuleBasedBreakIterator.isBoundary (RuleBasedBreakIterator.java:549)
  at android.text.method.WordIterator.isBoundary (WordIterator.java:102)
  at android.widget.Editor$SelectionHandleView.positionAtCursorOffset (Editor.java:7885)
  at android.widget.Editor$HandleView.invalidate (Editor.java:5998)
  at android.widget.Editor$SelectionModifierCursorController.invalidateHandles (Editor.java:8845)
  at android.widget.Editor.invalidateHandlesAndActionMode (Editor.java:2527)
  at android.widget.TextView.spanChange (TextView.java:12114)
  at android.widget.TextView$ChangeWatcher.onSpanRemoved (TextView.java:15309)
  at android.text.SpannableStringBuilder.sendSpanRemoved (SpannableStringBuilder.java:1310)
  at android.text.SpannableStringBuilder.removeSpan (SpannableStringBuilder.java:515)
  at android.text.SpannableStringBuilder.removeSpan (SpannableStringBuilder.java:815)
  at android.text.SpannableStringBuilder.removeSpan (SpannableStringBuilder.java:803)
  at androidx.emoji2.text.SpannableBuilder.removeSpan (SpannableBuilder.java:179)
  at net.twisterrob.inventory.android.content.model.helpers.Hinter.unhighlight (Hinter.java:56)
  at net.twisterrob.inventory.android.fragment.data.BaseEditFragment.updateHint (BaseEditFragment.java:298)
  at net.twisterrob.inventory.android.fragment.data.BaseEditFragment.access$600 (BaseEditFragment.java:57)
  at net.twisterrob.inventory.android.fragment.data.BaseEditFragment$6.onTextChanged (BaseEditFragment.java:209)
  at android.widget.TextView.sendOnTextChanged (TextView.java:11881)
  at android.widget.TextView.handleTextChanged (TextView.java:12010)
  at android.widget.TextView$ChangeWatcher.onTextChanged (TextView.java:15271)
  at android.text.SpannableStringBuilder.sendTextChanged (SpannableStringBuilder.java:1281)
  at android.text.SpannableStringBuilder.replace (SpannableStringBuilder.java:590)
  at androidx.emoji2.text.SpannableBuilder.replace (SpannableBuilder.java:315)
  at android.text.SpannableStringBuilder.delete (SpannableStringBuilder.java:232)
  at androidx.emoji2.text.SpannableBuilder.delete (SpannableBuilder.java:337)
  at androidx.emoji2.text.SpannableBuilder.delete (SpannableBuilder.java:49)
  at android.widget.TextView.deleteText_internal (TextView.java:14763)
  at android.widget.TextView.onTextContextMenuItem (TextView.java:13880)
  at androidx.appcompat.widget.AppCompatEditText.onTextContextMenuItem (AppCompatEditText.java:367)
  at android.widget.Editor$TextActionModeCallback.onActionItemClicked (Editor.java:5371)
  at com.android.internal.policy.DecorView$ActionModeCallback2Wrapper.onActionItemClicked (DecorView.java:5691)
  at com.android.internal.view.FloatingActionMode$3.onMenuItemSelected (FloatingActionMode.java:97)
  at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected (MenuBuilder.java:788)
  at com.android.internal.view.menu.MenuItemImpl.invoke (MenuItemImpl.java:160)
  at com.android.internal.view.menu.MenuBuilder.performItemAction (MenuBuilder.java:935)
  at com.android.internal.view.menu.MenuBuilder.performItemAction (MenuBuilder.java:925)
  at com.android.internal.view.FloatingActionMode.lambda$setFloatingToolbar$0$com-android-internal-view-FloatingActionMode (FloatingActionMode.java:128)
  at com.android.internal.view.FloatingActionMode$$ExternalSyntheticLambda0.onMenuItemClick
  at com.android.internal.widget.floatingtoolbar.LocalFloatingToolbarPopup$2.onClick (LocalFloatingToolbarPopup.java:203)
  at android.view.View.performClick (View.java:7892)
  at android.view.View.performClickInternal (View.java:7869)
  at android.view.View.-$$Nest$mperformClickInternal
  at android.view.View$PerformClick.run (View.java:30891)
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8762)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:604)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)
TWiStErRob commented 5 months ago

Tried to reproduce by interacting with the emulator's text selection popup, but no luck.

I compared the stack, and the only "destructive" action I have is "Paste", using that triggers a different code path:

image

"Cut" doesn't even call unhighlight, because the "title validation" stops it (empty => error state)

TWiStErRob commented 5 months ago

deleteText_internal is only used in "Cut": image

Selecting the the last 3 characters of a 4-letter word and cutting it reproduced the issue.

TWiStErRob commented 5 months ago

Repro:

  1. Set Highlight matches in Settings
  2. Create new item
  3. Enter "abcd"
  4. Select "cd"
  5. Cut