[Crashlytics] NullPointerException in getBinding() after view destroyed – VolunteerActivity, NewBenRegFragment, TBScreeningFormFragment (60 events)

XMLWordPrintable

    • STOP TB Sprint 12

      Summary

      NullPointerException in getBinding() when UI updates run after the Activity/Fragment view has been destroyed (VolunteerActivity, NewBenRegFragment, TBScreeningFormFragment).

      Background / Context

      Source: StopTB Android Crashlytics RCA (Oct 15–21 2026, release 2.2.3). RCA ref RCA-05, status: Probable Root Cause. Code inspected: release-2.2.3, commit cd02b155 (only VolunteerActivity inspected). Priority: P1 (VolunteerActivity), P2/P3 for the others. 60 events across 3 issues.

      Problem Statement

      UI update runs after the activity or fragment view has been destroyed, so the _binding!! getter hits null.

      Current Behaviour (Actual)

      • VolunteerActivity.startCampHubReconnect posts {{runOnUiThread { refreshCampHubOfflineBanner() }

        }} from an IO coroutine; _binding is nulled in onDestroy, so the getter throws (VolunteerActivity.kt line 129 in release-2.2.3; crash line 124).

      • Binding is not guarded against lifecycle end; network callbacks and coroutines outlive the view.

      Crashlytics issues:

      1. VolunteerActivity.getBinding (VolunteerActivity.kt:124) — 50 events / 44 users — repetitive, 1.1.4→2.2.3, 3 variants
      2. NewBenRegFragment.getBinding (NewBenRegFragment.kt:64) — 8 / 6 — 2.0.3→2.2.3, 2 variants (file not inspected)
      3. TBScreeningFormFragment.getBinding (TBScreeningFormFragment.kt:52) — 2 / 2 — seen only 2.2.0–2.2.1 (file not inspected)

      Expected Behaviour / Requirement

      No crash when async work completes after the view is destroyed; UI updates are skipped when the view/binding no longer exists.

      User Story

      As a volunteer using the app, I want screens to stay stable during rotation, backgrounding or reconnect, so that I do not lose my in-progress work.

      Acceptance Criteria

      • Given a camp hub reconnect in progress, When the device is rotated or the app is backgrounded/closed, Then no crash occurs (CAPA-12).
      • Given VolunteerActivity, When _binding is null or the activity is finishing, Then UI updates are skipped; jobs are cancelled and callbacks unregistered in onDestroy.
      • Given NewBenRegFragment and TBScreeningFormFragment, When inspected, Then the same pattern is fixed where present.
      • (Preventive, CAPA-13) Lint rule against _binding!! getters passes; view work scoped to viewLifecycleOwner.

      Business Rules / Validations

      None identified.

      Dependencies

      None identified.

      Impact / Affected Areas

      VolunteerActivity.kt (binding getter, startCampHubReconnect, onDestroy), NewBenRegFragment.kt, TBScreeningFormFragment.kt; Camp Hub reconnect flow.

      Out of Scope

      App-wide refactor of all view bindings beyond the lint rule [TBD whether lint rule is in this ticket].

      QA / Testing Considerations

      Rotate and background the app during hub reconnect; repeat on New Beneficiary Registration and TB Screening form; confirm no new NPE events in Crashlytics post-release.

      Open Questions / Clarifications

      • NewBenRegFragment and TBScreeningFormFragment not inspected; same root cause assumed from listing only [TBD].
      • Is CAPA-13 (lint rule) to be delivered in 2.5 or tracked separately?

      Source: StopTB_Crashlytics_RCA.xlsx (RCA-05, CAPA-12, CAPA-13).

              Assignee:
              Puneet Sharma
              Reporter:
              Shivani Garg
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: