Skip to content

fix(navigation): prevent ArrayIndexOutOfBoundsException on back navigation (COLUMBA-BF) - #1040

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/columba-bf-back-handler
Open

fix(navigation): prevent ArrayIndexOutOfBoundsException on back navigation (COLUMBA-BF)#1040
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/columba-bf-back-handler

Conversation

@sentry

@sentry sentry Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an ArrayIndexOutOfBoundsException that occurred when navigating back to a root tab (e.g., /chats) from another screen.

Root Cause:
The DoubleBackToExitHandler composable used BackHandler(enabled = currentRoute == route). During a back navigation gesture, currentRoute would update before the gesture completed, causing the enabled state to flip. This led to the BackHandler being re-registered or unregistered while the OnBackPressedDispatcher's callbacks array was being iterated, resulting in a concurrent modification and the ArrayIndexOutOfBoundsException.

Solution:

  1. Removed the route: String parameter from DoubleBackToExitHandler.
  2. Removed the enabled = currentRoute == route condition from the BackHandler within DoubleBackToExitHandler.
  3. Updated all call sites of DoubleBackToExitHandler to no longer pass the route argument.

By removing the explicit enabled condition, the BackHandler now relies on Navigation Compose's lifecycle management. Since DoubleBackToExitHandler is called within each composable(route) { ... } block, the BackHandler is automatically tied to the NavBackStackEntry's lifecycle, ensuring it is only active when the corresponding screen is on the back stack. This prevents the mid-gesture state changes that caused the crash.

Fixes COLUMBA-BF

@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Prevents a back-navigation crash by keeping root-tab back callbacks stable during navigation gestures.

  • Removes route-based enablement from DoubleBackToExitHandler.
  • Updates the Chats, Contacts, Map, and Settings root destinations to use the parameterless handler.

Confidence Score: 5/5

The PR appears safe to merge, with the back handler remaining scoped to the active root destination.

The changed handler removes unstable route-based enablement while preserving root-only double-back-to-exit behavior through each destination composable's lifecycle.

Important Files Changed

Filename Overview
app/src/main/java/network/columba/app/MainActivity.kt The root-tab back handlers are now unconditionally enabled only while their destination composable is active, avoiding callback registration changes during an in-progress back gesture.

Reviews (1): Last reviewed commit: "fix(navigation): prevent ArrayIndexOutOf..." | Re-trigger Greptile

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

0 participants