Closed Bug 1907286 Opened 1 year ago Closed 1 year ago

IllegalStateException calling requireContext in TranslationsDialogFragment

Categories

(Firefox for Android :: Translations, defect, P1)

Firefox 128
All
Android
defect

Tracking

()

RESOLVED FIXED
130 Branch
Tracking Status
firefox128 + fixed
firefox129 + fixed
firefox130 + fixed

People

(Reporter: polly, Assigned: olivia)

References

()

Details

(Keywords: crash, regression, topcrash, Whiteboard: [fxdroid][foundation][translations:130])

Crash Data

Attachments

(1 file)

Spotted in crash telemetry. Stack trace is

Exception java.lang.IllegalStateException:
  at androidx.fragment.app.Fragment.requireContext (Fragment.java:972)
  at androidx.fragment.app.Fragment.getResources (Fragment.java:1036)
  at org.mozilla.fenix.translations.TranslationsDialogFragment.onCreateDialog$lambda$1$lambda$0 (TranslationsDialogFragment.java:83)
  at android.app.Dialog$ListenersHandler.handleMessage (Dialog.java:1501)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:224)
  at android.os.Looper.loop (Looper.java:318)
  at android.app.ActivityThread.main (ActivityThread.java:8772)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:561)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1013)
Crash Signature: [@ java.lang.IllegalStateException: at androidx.fragment.app.Fragment.requireContext(Fragment.java) ]
Keywords: crash, regression
See Also: → 1812181
Component: General → Translations

This TranslationsDialogFragment crash was a regression in Fx 126.

Gabriel, do you have any insight into this bug? I'll try to figure out more too.

Flags: needinfo?(giorga)
Whiteboard: [fxdroid][foundation][translations:130]

Looks like we have had many previous similar issues from using requireContext().
It is likely to be difficult to reproduce but easy to fix.
I agree with Arturo's suggestion in this related crash: https://github.com/mozilla-mobile/fenix/issues/8408#issuecomment-585990538

I think we should use navigateSafe method when we open the TranslationsDialogFragment.
val directions =
BrowserFragmentDirections.actionBrowserFragmentToTranslationsDialogFragment()
navController.navigateSafe(R.id.browserFragment, directions)
In MenuNavigationMiddleware is used without navigateSafe like this :
is MenuAction.Navigate.Translate -> navController.nav(
R.id.menuDialogFragment,
MenuDialogFragmentDirections.actionMenuDialogFragmentToTranslationsDialogFragment(),
)
Maybe from here is the bug.

Flags: needinfo?(giorga)

The bug is linked to a topcrash signature, which matches the following criterion:

  • Top 10 AArch64 and ARM crashes on release

For more information, please visit BugBot documentation.

Keywords: topcrash

I'll work on a speculative fix today based on that information, thanks for the information and suggestions!

Assignee: nobody → ohall

Attempt to fix IllegalStateException in TranslationsDialogFragment.

  • Added navigateSafe to MenuNavigationMiddleware
  • Added runIfFragmentIsAttached to places where findNavController().popBackStack() was used in the translations area
Pushed by ohall@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/ab640abf079a IllegalStateException calling requireContext in TranslationsDialogFragment r=android-reviewers,pollymce
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 130 Branch

The patch landed in nightly and beta is affected.
:olivia, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox129 to wontfix.

For more information, please visit BugBot documentation.

Flags: needinfo?(ohall)

Comment on attachment 9412503 [details]
Bug 1907286 - IllegalStateException calling requireContext in TranslationsDialogFragment

Beta/Release Uplift Approval Request

  • User impact if declined: More crashes in the Android translations area.
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce: Not an easily tested code path to reproduce a crash.
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): The change is not particularly risky because this patch only adds guard statements to prevent trying to get a context when one is not available. However, this patch is a speculative crash fix and cannot be easily tested.
  • String changes made/needed:
  • Is Android affected?: Yes
Flags: needinfo?(ohall)
Attachment #9412503 - Flags: approval-mozilla-beta?
Severity: -- → S2
Priority: -- → P1

Comment on attachment 9412503 [details]
Bug 1907286 - IllegalStateException calling requireContext in TranslationsDialogFragment

Approved for 129.0b5

Attachment #9412503 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

Please nominate this for Release approval too.

Flags: needinfo?(ohall)

Comment on attachment 9412503 [details]
Bug 1907286 - IllegalStateException calling requireContext in TranslationsDialogFragment

Beta/Release Uplift Approval Request

  • User impact if declined: More crashes in the Android translations area.
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce: Not an easily tested code path to reproduce a crash.
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): The change is not particularly risky because this patch only adds guard statements to prevent trying to get a context when one is not available. However, this patch is a speculative crash fix and cannot be easily tested.
  • String changes made/needed:
  • Is Android affected?: Yes
Flags: needinfo?(ohall)
Attachment #9412503 - Flags: approval-mozilla-release?

Comment on attachment 9412503 [details]
Bug 1907286 - IllegalStateException calling requireContext in TranslationsDialogFragment

Approved for 128.0.2

Attachment #9412503 - Flags: approval-mozilla-release? → approval-mozilla-release+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: