Skip to content

Fix crash when a profile drag ends during layout - #190

Open
DaniilBorovskiy1809 wants to merge 1 commit into
throneproj:mainfrom
DaniilBorovskiy1809:fix/drag-end-during-layout
Open

DaniilBorovskiy1809 wants to merge 1 commit into
throneproj:mainfrom
DaniilBorovskiy1809:fix/drag-end-during-layout

Conversation

@DaniilBorovskiy1809

@DaniilBorovskiy1809 DaniilBorovskiy1809 commented Dec 5, 2026 •

Copy link
Copy Markdown

Problem

The app can crash when a profile drag ends while the list is laying out:

java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
    at androidx.recyclerview.widget.RecyclerView.assertNotInLayoutOrScroll
    at io.nekohasekai.sagernet.ui.profiles.ProfileListAdapter.notifyState
    at io.nekohasekai.sagernet.ui.ConfigurationFragment.onSelectionModeChanged
    at io.nekohasekai.sagernet.ui.profiles.SelectionMode.finish
    at io.nekohasekai.sagernet.ui.profiles.SelectionMode.onDragFinished
    at io.nekohasekai.sagernet.ui.profiles.ProfileListAdapter.endDrag
    at io.nekohasekai.sagernet.ui.profiles.ProfileListFragment$attachDragHelper$1.clearView
    at androidx.recyclerview.widget.ItemTouchHelper.select
    at androidx.recyclerview.widget.ItemTouchHelper.onChildViewDetachedFromWindow
    at androidx.recyclerview.widget.RecyclerView.dispatchLayout

ItemTouchHelper can call clearView() from RecyclerView.dispatchLayout() when the dragged row is detached. adapter.endDrag() then finishes the selection started by the drag's long press and calls notifyItemRangeChanged(), which RecyclerView does not allow while computing a layout.

Fix

Post endDrag() to the list so the selection is finished after the current layout pass. This matches the existing clearView() handling in DnsServerListDialog.

The stack trace was reproduced on 2.0.7; the same code path is still present on main.

ItemTouchHelper can call clearView() from RecyclerView.dispatchLayout() when the dragged row is detached. endDrag() then finishes the selection started by the long press and notifies the rows, which RecyclerView forbids while it is laying out. Post endDrag() so the selection finishes after the layout.
@DaniilBorovskiy1809
DaniilBorovskiy1809 force-pushed the fix/drag-end-during-layout branch from 764e64b to 5624143 Compare December 5, 2026 17:48
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.

1 participant