[Crashlytics] Fragment lifecycle crashes — BenIfaForm, CUFYForm, NewChildAsBenRegistration (detached fragment, null binding, lateinit adapter)

XMLWordPrintable

    • FLW Sprint 56
    • FLW Mobile App
    • Prod

      Summary

      Crashes from fragment/view lifecycle misuse: navigation or UI work after the fragment is detached, null view binding, unregistered camera launcher, and uninitialised lateinit adapter.

      Background / Context

      Source: Sakhi/Niramay Crashlytics RCA (Oct 12 – Nov 10 2026, latest release 2.13.0 (70)). RCA ref RCA-05, status: Probable Root Cause (stack traces not opened; reproduction steps unknown). Code inspected: PSMRI/FLW-Mobile-App, main, commit f90f07c3. 143 events across 9 issues; 123 are on the now-closed NewBenRegFragment issue (guards present in main). Remaining open call sites still match the crash lines in main.

      Problem Statement

      UI and navigation work runs after suspension points or lifecycle changes without isAdded / view-lifecycle checks.

      Current Behaviour (Actual)

      Open issues (events / users, versions):

      • BenIfaFormFragment$handleFormSubmission$3 (BenIfaFormFragment.kt:307) — IllegalStateException "not associated with a fragment manager" — 2 / 2 — 2.8.7 → 2.12.1. Code: {{lifecycleScope.launch { viewModel.saveFormResponses(...); findNavController()... }

        }} — navigation after a suspend call.

      • CUFYFormFragment.launchCamera (CUFYFormFragment.kt:456) — unregistered ActivityResultLauncher — 1 / 1 — 2.12.1. Line 456 = cameraLauncher.launch(tempCameraUri).
      • CUFYFormFragment.handleFormSubmission (CUFYFormFragment.kt:468) — lateinit adapter not initialised — 1 / 1 — 2.12.1. Line 468 = adapter.getUpdatedFields().
      • NewChildAsBenRegistrationFragment.getBinding (:39) — NullPointerException — 1 / 1 — 2.12.1 (fresh). Line 39 = _binding!!.

      Closed/muted (last seen ≤ 2.12.1): NewBenRegFragment (123 / 70, now guarded with isAdded + currentDestination), Hilt_CbacFragment.onGetLayoutInflater (7 / 5), EyeSurgeryFormFragment (4 / 3), IncentivesFragment (2 / 2), FragmentStore "Fragment already added" (2 / 2).

      Expected Behaviour / Requirement

      No crash when saves, camera flows or async work complete after the fragment/view is gone; views and launchers are used only when ready.

      User Story

      As a field user filling in forms, I want screens to stay stable during save, camera use, rotation and back-navigation, so I do not lose my work.

      Acceptance Criteria

      • Given BenIfaFormFragment, When back-press/rotation happens during save, Then no crash; navigation is guarded (isAdded / view lifecycle) or driven by a view-model event (CAPA-14).
      • Given CUFYFormFragment, When camera is launched or the form is submitted early, Then the launcher is registered before use and adapter initialisation is guarded (CAPA-14).
      • Given NewChildAsBenRegistrationFragment, When async work finishes after the view is destroyed, Then _binding is not dereferenced (CAPA-14).
      • Given lint, When a _binding!! getter or post-suspend UI work without lifecycle check is added, Then lint flags it (CAPA-15).

      Business Rules / Validations

      None identified.

      Dependencies

      None.

      Impact / Affected Areas

      BenIfaFormFragment.kt, CUFYFormFragment.kt, NewChildAsBenRegistrationFragment.kt; closed-issue fragments (Hilt_CbacFragment, EyeSurgery, Incentives) to be checked for the same pattern.

      Out of Scope

      Redesign of form architecture.

      QA / Testing Considerations

      Back-press and rotate during save; camera launch/return and process recreation on CUFY; submit before schema loads; confirm no new events at these lines on 2.13.x/3.0.

      Open Questions / Clarifications

      • Where is cameraLauncher registered in CUFYFormFragment (registration site not checked)?
      • Reproduction steps for BenIfa / CUFY crashes.

      Source: Sakhi_Niramay_Crashlytics_RCA.xlsx (RCA-05, CAPA-14, CAPA-15). RCA is a draft pending human confirmation.

              Assignee:
              Ishwar Chouhan
              Reporter:
              Shivani Garg
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: