Skip to content

Android crash: IndexOutOfBoundsException in Compose MultiSelectionLayout on mouse selection in SelectionContainer (1.3.1 (35)) #942

Closed

Description

@ivanfenenko

Crashlytics issue id: a34175e57d4cd343ec43f9d330ccada0 (Android, dev.opencode.mobile)
Console: https://console.firebase.google.com/project/opencode-mobile-release/crashlytics/app/android:dev.opencode.mobile/issues/a34175e57d4cd343ec43f9d330ccada0

Summary

Fatal java.lang.IndexOutOfBoundsException: Index 19 out of bounds for length 19 thrown from Compose text selection, triggered by a mouse selection gesture inside a SelectionContainer.

  • Blame frame: jdk.internal.util.Preconditions.outOfBounds, reached from ArrayList.get in androidx.compose.foundation.text.selection.MultiSelectionLayout.getCrossStatus (SelectionLayout.kt:184).
  • First seen 2026-11-01 18:33 CET. Crashlytics flags it SIGNAL_FRESH.
java.lang.IndexOutOfBoundsException: Index 19 out of bounds for length 19
  at java.util.ArrayList.get (ArrayList.java:434)
  at androidx.compose.foundation.text.selection.MultiSelectionLayout.getCrossStatus (SelectionLayout.kt:184)
  at androidx.compose.foundation.text.selection.MultiSelectionLayout.startOrEndSlotToIndex (SelectionLayout.kt:295)
  at androidx.compose.foundation.text.selection.MultiSelectionLayout.getStartInfo (SelectionLayout.kt:188)
  at androidx.compose.foundation.text.selection.SelectionAdjustment$Companion.None$lambda$0 (SelectionAdjustment.java:46)
  at androidx.compose.foundation.text.selection.SelectionManager.updateSelection (SelectionManager.kt:1447)
  at androidx.compose.foundation.text.selection.SelectionManager.startSelection (SelectionManager.kt:1406)
  at androidx.compose.foundation.text.selection.SelectionRegistrarImpl.notifySelectionUpdateStart (SelectionRegistrarImpl.kt:233)
  at androidx.compose.foundation.text.modifiers.SelectionModifierNodeKt$DefaultMouseSelectionObserver$1.onStart (SelectionModifierNode.kt:254)
  at androidx.compose.foundation.text.selection.SelectionGesturesKt.mouseSelection (SelectionGestures.kt:294)
  at androidx.compose.foundation.text.selection.SelectionGesturesKt$awaitSelectionGestures$2.invokeSuspend (SelectionGestures.kt:124)
  ... frames omitted ...

Counts (Crashlytics, as of 2026-11-02 09:12 CET)

  • 1 event / 1 user, on 1.3.1 (35), the newest Android release build (Android Release run 35, 31c38b72cb). Build 35 has 1136 sessions / 245 users in Crashlytics since 2026-10-27.
  • Device: Lenovo TB320FC (Legion Tab), Android 15, portrait, foreground. Breadcrumbs: the user opened a session from Home a few times, then crashed in session_chat about 50 s later.

Root-cause hypothesis

This is a Compose Foundation bug in multi-selectable selection. Our code is involved only because it puts many Text selectables in one SelectionContainer. The mouse path (mouseSelection → DefaultMouseSelectionObserver.onStart) starts a selection at the press position. When the press lands below/after the last selectable in the container, the start slot resolves to selectables.size, and MultiSelectionLayout.getCrossStatus indexes past the end: here, slot 19 of 19 selectables. The same crash is tracked upstream for Compose Multiplatform as CMP-10573 ("SelectionContainer IndexOutOfBoundsException from MultiSelectionLayout.crossStatus when the mouse is pressed below the last…"), fixed there in JetBrains/compose-multiplatform-core#3268 / #3270. Touch input uses a different gesture path, which explains why only a mouse/trackpad tablet user hits it.

Where this happens in our code: OpenCodeRenderedMarkdown wraps all markdown blocks of an assistant message in one SelectionContainer (ui/components/chat/OpenCodeRenderedMarkdown.kt, around line 168). Each paragraph, heading or list item adds a selectable, which fits 19 selectables. A press on bubble padding, a code block, a divider or a gallery after the last text block is enough. OpenCodeAssistantMessage.kt (plain-text fallback), ToolResultSheet.kt and OpenCodeSessionComposer.kt also use SelectionContainer and should get the same guard.

Compose BOM is 2026.09.00 both in run 35 and on main (e8d512b). The SelectionContainer wrapping is unchanged on main, so no fix is merged.

Possible fixes:

  • Check whether a newer Compose Foundation (BOM) release contains the upstream fix, and bump.
  • Until then, guard against it: for example, don't let mouse presses outside the text bounds start a selection, or give each markdown block its own SelectionContainer, or catch the case around the selection container.
  • Related: Keyboard and mouse support #869 (keyboard and mouse support).

Activity

  1. added
    bug
    android
    priority: high
    crash
    on Nov 2, 2026
  2. added a commit that references this issue on Nov 2, 2026
    fb1cc6a
  3. ivanfenenko commented on Nov 3, 2026

    @ivanfenenko
    CollaboratorAuthor

    Crashlytics triage 2026-11-03: fix PR #945 (c2347c750a, merged 2026-11-02) closed this issue. It turns off ComposeFoundationFlags.isMouseSelectionBetweenTextEnabled through ComposeFoundationWorkarounds.

    • The fix isn't in any release yet. The latest Android Release run is OPE-38 Add review changes pill #35 (1.3.1, 31c38b72cb), and it's behind c2347c750a.
    • Crashlytics a34175e5 is still 1 event / 1 user, on 1.3.1 (35) only. Build 35 has had about 1452 sessions.
    • I'll close-confirm after a release build containing c2347c750a has been out for at least 7 days with real usage and 0 events.
    • Possibly related, watch only: a new Android issue 970e0c4e is also in Compose text selection. It's an IllegalArgumentException: Start(14) or End(0) is out of range [0..22) from SelectionController.draw → TextLayoutResult.getPathForRange, with 1 event on 1.2.1 (33), Android 12, Xiaomi. It's below the filing threshold, so I haven't filed an issue for it.
  4. ivanfenenko commented on Nov 4, 2026

    @ivanfenenko
    CollaboratorAuthor

    Crashlytics triage, 2026-11-04: the fix is now in a release build.

  5. ivanfenenko commented on Nov 6, 2026

    @ivanfenenko
    CollaboratorAuthor

    Crashlytics triage, 2026-11-06: a34175e5 has a second event, 2 events / 1 user in total, still no event on a build with the fix.

    • New event 2026-11-05 17:14 UTC on 1.3.1 (35) (Lenovo TB320FC, IndexOutOfBoundsException: Index 49 out of bounds for length 49). Build 35 predates c2347c750a, so this is not a regression.
    • Android 1.4.0 (37) (contains c2347c750a) has 400 sessions and 0 a34175e5 events. Build 37 was released 2026-11-03 11:40 CET, so the earliest close-confirm is 2026-11-10 11:40 CET.
  6. ivanfenenko commented on Nov 11, 2026

    @ivanfenenko
    CollaboratorAuthor

    Crashlytics triage, 2026-11-11: close-confirmed.

    • Fix c2347c750a (Android: stop mouse presses below message text crashing selection #945) ships in Android 1.4.0 (37), built 2026-11-03, so it has been out more than 7 days.
    • Build 37 has 546 sessions and 0 a34175e5 events. The last a34175e5 event was 2026-11-08, on build 35 (before the fix).
    • The crashing code path is disabled on main: ComposeFoundationWorkarounds.kt still sets isMouseSelectionBetweenTextEnabled = false.
    • a34175e5 is already CLOSED in the Crashlytics console.

    Leaving this issue closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidbugcrashpriority: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions