Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Embedded Capacitor: Fix BridgeFragment NullPointerException #3553

Merged
merged 3 commits into from
Sep 24, 2020

Conversation

fkirc
Copy link
Contributor

@fkirc fkirc commented Sep 14, 2020

Bug Report

Platform(s)

Android embedded use case.

Current Behavior

After deploying BridgeFragment.java to production, I noticed the following crash in Firebase Crashlytics:

Fatal Exception: java.lang.RuntimeException: Unable to destroy activity: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.getcapacitor.Bridge.onDestroy()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5193)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5227)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void com.getcapacitor.Bridge.onDestroy()' on a null object reference
at com.getcapacitor.BridgeFragment.onDestroy(BridgeFragment.java:178)
at androidx.fragment.app.Fragment.performDestroy(Fragment.java:2927)
at androidx.fragment.app.FragmentStateManager.destroy(FragmentStateManager.java:492)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1296)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1504)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManager.dispatchDestroy(FragmentManager.java:2609)
at androidx.fragment.app.Fragment.performDestroy(Fragment.java:2922)
at androidx.fragment.app.FragmentStateManager.destroy(FragmentStateManager.java:492)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1296)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManager.dispatchDestroy(FragmentManager.java:2609)
at androidx.fragment.app.FragmentController.dispatchDestroy(FragmentController.java:330)
at androidx.fragment.app.FragmentActivity.onDestroy(FragmentActivity.java:365)
at androidx.appcompat.app.AppCompatActivity.onDestroy(AppCompatActivity.java:242)
at android.app.Activity.performDestroy(Activity.java:8217)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1342)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5178)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5227)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

Expected Behavior

The above crash should not happen.

Code Reproduction

Android's fragment lifecycle is tedious to debug; therefore I refer to official Android instructions: https://developer.android.com/guide/components/fragments#Lifecycle
I prefer it to just comply with those instructions instead of trying to debug those edge cases.

Other Technical Details

Firebase Crashlytics showed that the crash occured on Android 10.

@carlpoole carlpoole merged commit 8ea982a into ionic-team:main Sep 24, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants