question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mosby 3.1.0 NPEs in Activity#onDestroy()

See original GitHub issue

After upgrading app to Mosby 3.1.0 crash analytics have started displaying crashes like:

java.lang.RuntimeException: Unable to destroy activity {p/p.a}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.hannesdorfmann.mosby3.mvp.MvpPresenter.detachView()' on a null object reference
	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4299)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4317)
	at android.app.ActivityThread.-wrap6(ActivityThread.java)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1569)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:241)
	at android.app.ActivityThread.main(ActivityThread.java:6274)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.hannesdorfmann.mosby3.mvp.MvpPresenter.detachView()' on a null object reference
	at com.hannesdorfmann.mosby3.mvp.delegate.ViewGroupMvpDelegateImpl.detachPresenterIfNotDoneYet(ViewGroupMvpDelegateImpl.java:301)
	at com.hannesdorfmann.mosby3.mvp.delegate.ViewGroupMvpDelegateImpl.onActivityDestroyed(ViewGroupMvpDelegateImpl.java:255)
	at android.app.Application.dispatchActivityDestroyed(Application.java:253)
	at android.app.Activity.onDestroy(Activity.java:1851)
	at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:358)
	at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
	at p.a.onDestroy(a.java:)
	at android.app.Activity.performDestroy(Activity.java:6922)
	at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1154)
	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4286)
	... 9 more

Do not have the specific repro steps available yet, but reading the source in ViewGroupMvpDelegateImpl:

  private void destroyPresenterIfnotDoneYet() {
    if (!presenterDestroeyed) {
      P presenter = delegateCallback.getPresenter();
      presenter.destroy();

To me this looks like the code is assuming too much about the fragment/activity lifecycle - the fragment lifecycle has not reached MvpFragment#onCreate() where the presenter is created but the the activity gets destroyed for some other reason, and presenterDestroeyed defaults to false.

For what it’s worth, there’s also a typo in presenterDestroeyed.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
sockeqwecommented, Sep 24, 2018

Working on it, along migrating to android x

0reactions
vladimirfxcommented, Mar 12, 2019

I don’t know actually. Stacktrace do not include either:

Caused by java.lang.NullPointerExceptionAttempt to invoke interface method 'void com.hannesdorfmann.mosby3.mvp.MvpPresenter.detachView()' on a null object reference Raw Text
--
  | com.hannesdorfmann.mosby3.ViewGroupMviDelegateImpl.detachPresenterIfNotDoneYet (ViewGroupMviDelegateImpl.java:275)
  | com.hannesdorfmann.mosby3.ViewGroupMviDelegateImpl.onActivityDestroyed (ViewGroupMviDelegateImpl.java:251)
  | android.app.Application.dispatchActivityDestroyed (Application.java:253)
  | android.app.Activity.onDestroy (Activity.java:1995)
  | android.support.v4.app.FragmentActivity.onDestroy (FragmentActivity.java:413)
  | android.support.v7.app.AppCompatActivity.onDestroy (AppCompatActivity.java:210)
  | android.app.Activity.performDestroy (Activity.java:7297)
  | android.app.Instrumentation.callActivityOnDestroy (Instrumentation.java:1250)
  | android.app.ActivityThread.performDestroyActivity (ActivityThread.java:4437)
  | android.app.ActivityThread.handleDestroyActivity (ActivityThread.java:4468)
  | android.app.ActivityThread.-wrap5 (Unknown Source)
  | android.app.ActivityThread$H.handleMessage (ActivityThread.java:1678)
  | android.os.Handler.dispatchMessage (Handler.java:106)
  | android.os.Looper.loop (Looper.java:171)
  | android.app.ActivityThread.main (ActivityThread.java:6651)
  | java.lang.reflect.Method.invoke (Method.java)
  | com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
  | com.android.internal.os.ZygoteInit.main (ZygoteInit.java:824)


Read more comments on GitHub >

github_iconTop Results From Across the Web

Activity - Android Developers
The entire lifetime of an activity happens between the first call to onCreate(Bundle) through to a single final call to onDestroy() . An...
Read more >
Ted Mosby - Software Architect - Hannes Dorfmann
Activity and Fragment seems to be both, because they have lifecycle callbacks like onCreate() or onDestroy() as well as responsibilities of ...
Read more >
How to update status in remote database if the activity's ...
... guarantee a method run no earlier than the activity's onDestroy() callback, an attractive solution is Android Jetpack's WorkManager for.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found