wordpress-mobile / WordPress-Android

WordPress for Android
http://android.wordpress.org
GNU General Public License v2.0
2.94k stars 1.31k forks source link

NullPointerException: autoCreateLinks(...) must not be null #20758

Open sentry-io[bot] opened 2 months ago

sentry-io[bot] commented 2 months ago

Sentry Issue: JETPACK-ANDROID-R4R

RuntimeException: Unable to start activity ComponentInfo{com.jetpack.android/org.wordpress.android.ui.posts.EditPostActivity}: java.lang.NullPointerException: autoCreateLinks(...) must not be null
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3946)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4126)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:108)
    at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:195)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:157)
...
(9 additional frame(s) were not displayed)

NullPointerException: autoCreateLinks(...) must not be null
    at org.wordpress.android.ui.posts.EditPostActivity.newPostFromShareAction(EditPostActivity.kt:451)
    val content = migrateToGutenbergEditor(AutolinkUtils.autoCreateLinks(text))
    at org.wordpress.android.ui.posts.EditPostActivity.handleIntentExtras(EditPostActivity.kt:665)
    newPostFromShareAction()
    at org.wordpress.android.ui.posts.EditPostActivity.onCreate(EditPostActivity.kt:533)
    handleIntentExtras(intent.extras, isRestarting)
...
(15 additional frame(s) were not displayed)
dangermattic commented 2 months ago

Thanks for reporting! 👍

thomashorta commented 2 months ago

It doesn't seem that this was in-fact introduced in 24.8, but there was recent code refactoring the EditPostActivity to Kotlin which caused this new crash signature when the text passed to autoCreateLinks is null, I believe.

@zwarm since you probably know more about this context and the Kotlin conversion, I am assigning you to the crash, but feel free to assign to someone else if it makes sense.

I did a quick investigation and it looks like the issue is that autoCreateLinks can return null, but it's not marked as @Nullable, so the Kotlin code doesn't complain in compilation time and crashes in that scenario in runtime.

https://github.com/wordpress-mobile/WordPress-Android/blob/e796f20f39146eb92e75c8f274246f614b940ff2/WordPress/src/main/java/org/wordpress/android/util/AutolinkUtils.java#L74-L76

I believe we need to properly handle the case of text or autoCreateLinks being null to avoid this crash.

zwarm commented 2 months ago

@thomashorta - Exactly. In the java class only the first use of autoCreateLinks was checking for nulls before usage, the second use of the method was not. I am raising a PR against release/24.8 to check for nulls and if so, then send empty text instead. The jave code would have also crashed because it did not prevent nulls from being passed along. :(

sentry-io[bot] commented 2 months ago

Sentry Issue: WORDPRESS-ANDROID-2YCN