Skip to content

Unguarded navigation calls crash app with IllegalArgumentException #163

@sande11

Description

@sande11

Summary

Two fatal crashes were reported in Crashlytics where Jetpack Navigation throws IllegalArgumentException because a navigation action is called from the wrong current destination. Both crashes occur on the same device session date (Apr 9 2026) and share the same root cause.

Crashes

Issue 522fe5fc — SubChapterFragment → BodyFragment


IllegalArgumentException: Navigation action/destination
action_subChapterFragment_to_bodyFragment cannot be found
from the current destination bodyFragment
at SubChapterFragment.onViewCreated$lambda$2(SubChapterFragment.kt:77)
Issue 5bd6be20 — MainFragment → SavedFragment
IllegalArgumentException: Navigation action/destination
action_mainFragment_to_savedFragment cannot be found
from the current destination chapterFragment
at MainFragment.onViewCreated$lambda$0(MainFragment.kt:237)

Root cause

Both crashes are triggered by a stale onKeyUp event (hardware key / D-pad) firing after a touch event has already completed the navigation. By the time the key-up fires, the current destination has changed and the action no longer exists from it.

Neither call site guards against this:


// SubChapterFragment.kt:77 — no destination check
findNavController().navigate(subChapterFragmentDirections)

// MainFragment.kt:237 — no destination check
findNavController().navigate(this)

Fix
Wrap each navigate() call with a current destination check before navigating:


// SubChapterFragment.kt
if (findNavController().currentDestination?.id == R.id.subChapterFragment) {
    findNavController().navigate(subChapterFragmentDirections)
}

// MainFragment.kt
if (findNavController().currentDestination?.id == R.id.mainFragment) {
    findNavController().navigate(MainFragmentDirections.actionMainFragmentToSavedFragment())
}

Scope

  • MainFragment.kt
  • BodyFragment.kt
  • SubChapterFragment.kt
  • ChapterFragment.kt, ChartFragment.kt, SavedFragment.kt, GlobalSearchFragment.kt, SettingsFragment.kt,

All of these are vulnerable to the same crash. The fix should be applied consistently across all call sites.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions