-
-
Notifications
You must be signed in to change notification settings - Fork 45
CCCT-1990 BaseConnectFragment NPE Crash #3470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CCCT-1990 BaseConnectFragment NPE Crash #3470
Conversation
Added checks to API callbacks for the case that the respective fragment is added to the activity.
…nto bug/CCCT-1990-NPE-for-base-connect-fragment
📝 WalkthroughWalkthroughThis PR adds defensive lifecycle-aware guards across four Connect-related fragments to prevent UI operations when fragments are not attached to their parent activities. Specifically, isAdded() checks are inserted before UI updates and state changes in callback methods (onSuccess/onFailure paths) across ConnectDeliveryDetailsFragment, ConnectDeliveryProgressFragment, ConnectJobIntroFragment, and ConnectJobsListsFragment. Analytics calls remain unguarded. No public APIs or method signatures are modified. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🧰 Additional context used🧠 Learnings (16)📓 Common learnings📚 Learning: 2025-07-29T14:11:36.386ZApplied to files:
📚 Learning: 2025-07-29T14:10:58.243ZApplied to files:
📚 Learning: 2025-06-06T19:54:26.428ZApplied to files:
📚 Learning: 2025-05-08T11:08:18.530ZApplied to files:
📚 Learning: 2025-05-22T14:28:35.959ZApplied to files:
📚 Learning: 2025-04-18T20:13:29.655ZApplied to files:
📚 Learning: 2025-06-20T15:51:14.157ZApplied to files:
📚 Learning: 2025-06-06T19:52:53.173ZApplied to files:
📚 Learning: 2025-07-29T14:10:55.131ZApplied to files:
📚 Learning: 2025-02-19T15:15:01.935ZApplied to files:
📚 Learning: 2025-01-21T18:19:05.799ZApplied to files:
📚 Learning: 2025-05-22T14:26:41.341ZApplied to files:
📚 Learning: 2025-06-06T20:15:21.134ZApplied to files:
📚 Learning: 2025-05-09T10:57:41.073ZApplied to files:
📚 Learning: 2025-06-04T19:17:21.213ZApplied to files:
🧬 Code graph analysis (2)app/src/org/commcare/fragments/connect/ConnectJobsListsFragment.java (1)
app/src/org/commcare/fragments/connect/ConnectDeliveryDetailsFragment.java (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
OrangeAndGreen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will definitely be nice to stop getting those NPEs
|
@conroy-ricketts This looks good overall. This is just a though and need your views also @conroy-ricketts @OrangeAndGreen @shubham1g5 Your changes will definitely reduce the number of crashes but it cannot guarantee that it will stop crashes depending upon when |
|
@Jignesh-dimagi I think we are setting the binding to null to prevent memory leaks if I'm not mistaken |
|
But I do agree that these changes will not 100% guarantee the crashes stop completely, especially if we implement or change something in the future and we forget about these scenarios |
|
And also +1 on the comment about |
I don't think it's required to set to null. View is already getting destroyed. |
|
Agreed on all the above, #1 being that long-term we should get these moved to view model scopes. Additional thoughts:
|
|
@OrangeAndGreen @Jignesh-dimagi I just recently did some more testing on a build off of the For repro path 1, the app still crashes but with a different exception:
Screen_Recording_20251226_084028_CommCare.Debug.mp4For repro path 2, the app still crashes which makes sense because the crash here is the same one I saw the other day which is not directly related to the binding being null:
Screen_Recording_20251226_083440_CommCare.Debug.mp4So, I think that simply removing |
CCCT-1990
Technical Summary
This crash happens when we try to update the UI after an asynchronous API call if the user navigates away from the screen we are trying to update.
In other words, there are cases where we are attempting to retrieve the
binding(to update the UI) after it's set tonullinBaseConnectFragment.onDestroyView()(here).So, since we are incorrectly updating the UI, I searched through all of our Connect fragments and added checks to any fragment where we are updating the UI with that binding after an API call (if we weren't doing so already) so that this crash does not happen again. I actually fixed two crashes at the same time by doing this.
Repro Path 1 (Example of the original crash)
Screen_Recording_20251222_125928_CommCare.Debug.mp4
The app crashes here with
java.lang.NullPointerException at org.commcare.fragments.base.BaseConnectFragment.getBinding())- this is the original crash I reported in the ticket.With my changes, this is what the app looks like when it does not crash:
Screen_Recording_20251222_130417_CommCare.Debug.mp4
Repro Path 2 (A different but similar crash)
Screen_Recording_20251222_123008_CommCare.Debug.mp4
The app crashes here with
java.lang.IllegalStateException: Fragment ConnectJobIntroFragment... not attached to an activity.With my changes, this is what the app looks like when it does not crash:
Screen_Recording_20251222_124254_CommCare.Debug.mp4
I was not able to reproduce the app crashing when refreshing data (here and here) or confirming payments (here) in both the
ConnectJobsListsFragmentand theConnectDeliveryProgressFragment, which is actually a bit weird to me because the app should be crashing similarly to the two repro paths I outlined above unless I'm missing something. Regardless, I went ahead and added checks to those two fragments as well anyways because we are still using the binding to update the UI after an API call and it's good practice. Let me know if there are any objections to that.Safety Assurance
Safety story
I verified that I no longer see the app crash for the two repro paths above.
I verified that the app behaves as expected when not forcing a crash.
QA Plan
We should ensure that the app never crashes in the two repro paths I outlined above.