Crash in [@ java.lang.IllegalStateException: at androidx.fragment.app.Fragment.requireContext(Fragment.java)]
Categories
(Firefox for Android :: Downloads, defect)
Tracking
()
People
(Reporter: dmeehan, Assigned: giorga)
References
(Regression)
Details
(Keywords: crash, regression, topcrash)
Crash Data
Attachments
(3 files)
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
phab-bot
:
approval-mozilla-release+
|
Details | Review |
|
48 bytes,
text/x-phabricator-request
|
phab-bot
:
approval-mozilla-beta+
|
Details | Review |
Crash report: https://crash-stats.mozilla.org/report/index/ab33639b-020b-4009-8de1-5aa320260524
Top 10 frames:
0 androidx.fragment.app.Fragment requireContext Fragment.java:18
1 org.mozilla.fenix.browser.BaseBrowserFragment$$ExternalSyntheticLambda86 onDismiss R8$$SyntheticClass:6
2 android.app.Dialog$ListenersHandler handleMessage Dialog.java:1477
3 android.os.Handler dispatchMessage Handler.java:106
4 android.os.Looper loopOnce Looper.java:201
5 android.os.Looper loop Looper.java:288
6 android.app.ActivityThread main ActivityThread.java:8061
7 java.lang.reflect.Method invoke Method.java:-2
8 com.android.internal.os.RuntimeInit$MethodAndArgsCaller run RuntimeInit.java:703
9 com.android.internal.os.ZygoteInit main ZygoteInit.java:911
| Reporter | ||
Comment 1•9 days ago
|
||
This crash existed before 151, but there is an increase in volume compared to 150.
Claude thinks the regressor is Bug 2002273 for the following reason:
Trivial diff in behavior:
- Before: the dismiss handler used a context variable that was saved at the top of a much larger function. That saved
reference stays alive even after the fragment detaches, so the handler runs fine.
- After: the dialog code got moved into its own little helper method, showFirstPartyDownloadDialog. In moving it, the
dismiss handler stopped using the saved context and started calling requireContext() directly — which throws if the fragment
isn't attached.
That's the entire regression. It's a one-word change (context → requireContext()) introduced incidentally by a refactor, not
on purpose.
The fix
Re-save the context at the top of the helper method, then use the saved one in the dismiss handler — same shape as the
working sibling dialog on the previous line.
In mobile/android/fenix/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt, the showFirstPartyDownloadDialog
method (around line 2520):
private fun showFirstPartyDownloadDialog(
currentDownloadState: CurrentDownloadState,
positiveAction: PositiveActionCallback,
negativeAction: NegativeActionCallback,
) {
val context = context ?: return // ← add
…
downloadDialog = MaterialAlertDialogBuilder(context) // ← was requireContext()
…
.setOnDismissListener {
downloadDialog = null
context.components.analytics.crashReporter.recordCrashBreadcrumb( // ← was requireContext()
Breadcrumb("FirstPartyDownloadDialog onDismiss"),
)
}.show()
}
Two changes:
1. val context = context ?: return at the top — grabs the current context once, bails out cleanly if the fragment isn't
attached.
2. Replace both requireContext() calls inside the method with that saved context.
The dismiss handler now uses the captured reference, which stays valid even if the fragment detaches before the dialog
finishes dismissing. The crash goes away.
This is the same pattern the other (unchanged) dialog on line 776 of the same file uses correctly — Bug 2002273 just forgot
to carry the pattern over when it extracted the new method.
Could you take a look and confirm if Claude is correct?
| Assignee | ||
Comment 2•8 days ago
|
||
Updated•8 days ago
|
| Reporter | ||
Comment 3•8 days ago
|
||
Clearning NI since there is a patch. We could include this in the dot release next week.
Comment 4•8 days ago
|
||
The bug is linked to a topcrash signature, which matches the following criteria:
- Top 10 AArch64 and ARM crashes on nightly
- Top 10 AArch64 and ARM crashes on beta
For more information, please visit BugBot documentation.
Comment 6•4 days ago
|
||
| bugherder | ||
Comment 7•4 days ago
|
||
The patch landed in nightly and beta is affected.
:giorga, is this bug important enough to require an uplift?
- If yes, please nominate the patch for beta approval.
- See https://wiki.mozilla.org/Release_Management/Requesting_an_Uplift for documentation on how to request an uplift.
- If no, please set
status-firefox152towontfix.
For more information, please visit BugBot documentation.
| Assignee | ||
Comment 9•4 days ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D302274
Updated•4 days ago
|
Comment 10•4 days ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined/Reason for urgency: The app will crash
- Code covered by automated testing?: no
- Fix verified in Nightly?: yes
- Needs manual QE testing?: yes
- Steps to reproduce for manual QE testing: I don't have any.
- Risk associated with taking this patch: low
- Explanation of risk level: It was a if check.
- String changes made/needed?: no
- Is Android affected?: yes
| Assignee | ||
Updated•4 days ago
|
| Assignee | ||
Comment 11•4 days ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D302274
Updated•4 days ago
|
Comment 12•4 days ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined/Reason for urgency: The app will crash
- Code covered by automated testing?: no
- Fix verified in Nightly?: yes
- Needs manual QE testing?: yes
- Steps to reproduce for manual QE testing: I don't have any.
- Risk associated with taking this patch: low
- Explanation of risk level: It was a if check.
- String changes made/needed?: no
- Is Android affected?: yes
| Reporter | ||
Updated•4 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Comment 13•3 days ago
|
||
| uplift | ||
Updated•3 days ago
|
Updated•3 days ago
|
Comment 14•3 days ago
|
||
| uplift | ||
Updated•9 hours ago
|
Comment 15•7 hours ago
|
||
Verified there is no crash encountered while renaming the downloaded files.
Tested on Firefox for Android Beta 152.0b6 with Pixel Tablet 9Android 16), Xiaomi 12T (Android 12), and Asus Zenfone (Android 13).
Tested on Firefox for Android Nightly 153.0a1 from 6/1 on Pixel 6 (Android 17), and Huawei Pura 70 (Android 12).
Description
•