WordPress-Android
WordPress-Android copied to clipboard
NullPointerException
Sentry Issue: WORDPRESS-ANDROID-2YSX
NullPointerException: None
at org.wordpress.android.ui.posts.EditPostRepository.getFeaturedImageId(EditPostRepository.kt:84)
get() = post!!.featuredImageId
at org.wordpress.android.ui.posts.EditPostActivity.getGutenbergPropsBuilder(EditPostActivity.kt:2458)
val featuredImageId = editPostRepository.featuredImageId.toInt()
at org.wordpress.android.ui.posts.EditPostActivity.onXpostsSettingsCapability(EditPostActivity.kt:2451)
(editorFragment as GutenbergEditorFragment).updateCapabilities(gutenbergPropsBuilder)
at org.wordpress.android.ui.posts.EditPostActivity.access$updateOnSuccessfulUpload(EditPostActivity.kt:260)
@Suppress("LargeClass")
at org.wordpress.android.ui.posts.EditPostActivity.access$onXpostsSettingsCapability(EditPostActivity.kt:260)
@Suppress("LargeClass")
...
(14 additional frame(s) were not displayed)
Thanks for reporting! 👍
Sentry Issue: JETPACK-ANDROID-S3H
Investigation Notes
- This crash seemed to take off when the
sync_publishingfeature flag was switched to 100%. It has since been switched back toisAutomatticianand1%. The team has been unable to recreate the crash, but suspect some type of race condition possibly with the handling of theonPostChangedinStorePostViewModel. - There are an additional two places that might be causing the issue is
PostStore.getPostByLocalPostIdandPostStore.loadPostByRemotePostId. They will return null if the post can not be found, which will lead to setting the post to null inEditPostRepository.loadPostByLocalPostIdandEditPostRepository.loadPostByRemotePostId. The former method is called from thestorePostViewModel.onPostUpdateResult.observein EditPostActivity. If by some chance, the post is set to null it will screw up all subsequent calls.
fun loadPostByLocalPostId(postId: Int) {
reportTransactionState(true)
post = postStore.getPostByLocalPostId(postId)
savePostSnapshot()
reportTransactionState(false)
}
and
fun loadPostByRemotePostId(remotePostId: Long, site: SiteModel) {
reportTransactionState(true)
post = postStore.getPostByRemotePostId(remotePostId, site)
savePostSnapshot()
reportTransactionState(false)
}
Of course, if either of those methods I mentioned above are null it could throw a wrench into making a call to one of the properties. Not the best of situations.
Sentry Issue: JETPACK-ANDROID-1391
The above linked issue involves EditPostRepository.isPage, which like the original issue assumes post isn't null (post!!.isPage).
Rather than attempt to fix these issues as they arise, we should rethink how we handle nullness in EditPostRepository.