Wordpress-android: Crash NPE: When editor activity is recreated after being killed in background

Created on 31 Oct 2017  路  8Comments  路  Source: wordpress-mobile/WordPress-Android

Happens with both Visual and Aztec editors.

Steps to reproduce:

  1. Turn "Don't keep activities" on.
  2. Open any draft or published post (new post does not cause this crash).
  3. While at the editor screen press Home button to minimize the app.
  4. Return to the app, notice crash.
FATAL EXCEPTION: main
   Process: org.wordpress.android, PID: 20465
   java.lang.RuntimeException: Unable to start activity ComponentInfo{org.wordpress.android/org.wordpress.android.ui.posts.EditPostActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.wordpress.android.fluxc.model.PostModel.getPostFormat()' on a null object reference
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
       at android.app.ActivityThread.-wrap12(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6077)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.wordpress.android.fluxc.model.PostModel.getPostFormat()' on a null object reference
       at org.wordpress.android.ui.posts.EditPostSettingsFragment.fetchSiteSettingsAndUpdateDefaultPostFormatIfNecessary(EditPostSettingsFragment.java:168)
       at org.wordpress.android.ui.posts.EditPostSettingsFragment.onActivityCreated(EditPostSettingsFragment.java:154)
       at android.app.Fragment.performActivityCreated(Fragment.java:2361)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1014)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1153)
       at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2039)
       at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:176)
       at android.app.Activity.performCreateCommon(Activity.java:6658)
       at android.app.Activity.performCreate(Activity.java:6666)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
PostinEditing [Pri] High [Type] Bug [Type] Crash

All 8 comments

Duplicate of #6731 - I'm closing #6731, there are more details here.

I can't seem to be able to replicate this 馃槙 . Tried with Samsung Galaxy S3 (Android 4.2.2) and Google Pixel (Android 8.0), Visual, Aztec editors, branches release/8.5 and develop. Posts with and without text, images, etc.

Can you provide more specific conditions to test, @khaykov ? Thanks in advance

Thank's for trying, @mzorz ! I can confirm that it's indeed a bit tricky to reproduce this issue :)
After a couple of tries I came up with steps that work for me every time:

  1. Uninstall the WordPress app from your device.
  2. Turn "Don't keep activities" on.
  3. Install the app and log in.
  4. When prompted to try new editor press "NOT NOW".
  5. Navigate to posts list, and open any post.
  6. Go to App Settings, and change the editor to Beta.
  7. Navigate back to post list and open any post.
  8. While at the editor screen press Home button to minimize the app.
  9. Return to the app, notice crash.

I'm afraid it still doesn't work for me on the Google Pixel 馃槙
Could you offer all sorts of specifics, like Android version, a copy of the Post body that fails, and so on? Is this with the develop branch?
Would you like to try and maybe put a PR together on your end? Don't want to ask for too much but unless I can repro, I feel I can't help too much 馃槙

No problems, @mzorz ! I'll give it a shot - I suspect what the problem is, so probably would be easier to fix it then to look for why it's not reproducible.

So looks like it's a race condition of a sort. That's why it hasn't worked for you, @mzorz.

When you navigate to a post list, fresh posts are fetched, old posts are deleted and ID of all posts are incremented.

How it's causing this crash - you navigate to a post list, _immediately_ tap on a post, adapter opens the editor and sends local id of a post to it. In the meantime, the fetch action is finished in the background, all the posts are deleted and their ID changed. You still have a correct post in Editor, but its ID is out of date. Activity is destroyed and recreated. It's trying to get a post from PostStore using the original ID we sent to it but fails because it's no longer valid.

Thank's to @hypest for pinpointing the exact location of a problem.

Maybe @aforcier would be able give some more insight into this problem.

Awesome! 馃檱 thanks @khaykov and @hypest for taking the time to nail the root cause for this one

Closing via #6830

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jd-alexander picture jd-alexander  路  3Comments

reginabally picture reginabally  路  3Comments

khaykov picture khaykov  路  3Comments

maxme picture maxme  路  3Comments

mzorz picture mzorz  路  3Comments