Skip to content

Fix crash when a list updates while a screen reader reads an item - #1995

Open
mehranlatifi83 wants to merge 1 commit into
DrKLO:masterfrom
mehranlatifi83:fix/talkback-list-update-crash
Open

Fix crash when a list updates while a screen reader reads an item#1995
mehranlatifi83 wants to merge 1 commit into
DrKLO:masterfrom
mehranlatifi83:fix/talkback-list-update-crash

Conversation

@mehranlatifi83

Copy link
Copy Markdown

Summary

With a screen reader running, the app crashes from time to time when a list updates underneath it, most reliably when messages load into an empty chat that was opened from search, from a global search result or from a comment thread, and when scrolling to the end of comments loads more.

java.lang.IndexOutOfBoundsException: invalid position 61. State item count is 24
  at RecyclerView$Recycler.convertPreLayoutPositionToPostLayout
  at GridLayoutManager.getSpanGroupIndex
  at GridLayoutManager.onInitializeAccessibilityNodeInfoForItem
  at RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo
  at ChatMessageCell.onInitializeAccessibilityNodeInfo
  at ViewRootImpl.handleWindowContentChangedEvent
  ...
  at RecyclerView.dispatchContentChangedIfNecessary
  at RecyclerView.onExitLayoutOrScroll
  at RecyclerView.dispatchLayoutStep1

The list dispatches a content changed event from inside its layout pass. Because a screen reader holds accessibility focus on an item, the framework builds that item's node info right away, which asks the layout manager for the item position while the ongoing layout has not settled positions yet, and the stale position is out of range for the new state. Without a screen reader the node is never built, which is why it only happens with one running.

The delegate already ignores the layout manager while adapter updates are pending. This extends the same guard to a running layout pass. The node is filled again once the layout is over, so nothing is lost for the screen reader.

@mehranlatifi83
mehranlatifi83 force-pushed the fix/talkback-list-update-crash branch from 931ddce to 51e033a Compare July 31, 2026 14:16
@amirmahdifard

Copy link
Copy Markdown

@oldeepsmile-beep hi. Can this be merged? we always had problems why no one pays any attention to pull requests opened here. About accessibility, no one pays any attention to us, So we just started to send the pull requests our selves.

A content changed event dispatched at the end of a layout pass makes the
framework build the node info of the focused item right away, which asks
the layout manager for item positions that the finished layout has not
settled yet and throws IndexOutOfBoundsException. It shows up when
messages load underneath a screen reader, for example after opening a
message from search or scrolling comments.

Ignore the layout manager while positions are still pre layout, the same
way pending adapter updates are already ignored, and treat a position
that no longer exists as unknown instead of throwing.
@mehranlatifi83
mehranlatifi83 force-pushed the fix/talkback-list-update-crash branch from 51e033a to da2bd14 Compare August 3, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants