Skip to content

Fix Android crash mMarkdownStyle is null#152

Merged
tomekzaw merged 1 commit intomainfrom
@tomekzaw/fix-android-crash
Feb 5, 2024
Merged

Fix Android crash mMarkdownStyle is null#152
tomekzaw merged 1 commit intomainfrom
@tomekzaw/fix-android-crash

Conversation

@tomekzaw
Copy link
Collaborator

@tomekzaw tomekzaw commented Feb 5, 2024

Details

This PR fixes the following crash on Android that happens when returning back to the screen where MarkdownTextInput is mounted:

02-03 13:20:42.924 19312 19312 E AndroidRuntime: java.lang.NullPointerException: mMarkdownStyle is null
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at java.util.Objects.requireNonNull(Objects.java:232)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at com.expensify.livemarkdown.MarkdownUtils.a(SourceFile:5)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at f6.m.onTextChanged(SourceFile:14)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at com.facebook.react.views.textinput.g.onTextChanged(SourceFile:27)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.widget.TextView.sendOnTextChanged(TextView.java:12359)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.widget.TextView.handleTextChanged(TextView.java:12474)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:15887)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1268)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:577)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at androidx.emoji2.text.x.replace(SourceFile:7)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:508)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at androidx.emoji2.text.x.replace(SourceFile:4)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at androidx.emoji2.text.x.replace(SourceFile:1)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.view.inputmethod.BaseInputConnection.replaceTextInternal(BaseInputConnection.java:1026)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:962)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:241)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at com.android.internal.inputmethod.EditableInputConnection.commitText(EditableInputConnection.java:222)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.view.inputmethod.InputConnectionWrapper.commitText(InputConnectionWrapper.java:207)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.view.inputmethod.InputConnectionWrapper.commitText(InputConnectionWrapper.java:207)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at com.facebook.react.views.textinput.i.commitText(SourceFile:32)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.view.inputmethod.RemoteInputConnectionImpl.lambda$commitText$17(RemoteInputConnectionImpl.java:649)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.view.inputmethod.RemoteInputConnectionImpl.$r8$lambda$jG8e73WUDH3moNu5UWHEmrz2eOk(Unknown Source:0)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.view.inputmethod.RemoteInputConnectionImpl$$ExternalSyntheticLambda18.run(Unknown Source:8)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:958)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.os.Looper.loopOnce(Looper.java:205)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:294)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:8248)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
02-03 13:20:42.924 19312 19312 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

Most likely the root cause of the crash is that onDetachedFromWindow resets mMarkdownStyle and when the component gets mounted again, onAttachedToWindow is called before setMarkdownStyle and thus applyMarkdownFormatting has null mMarkdownStyle and Object.assertNonNull fails.

Related Issues

Fixes Expensify/App#35765

Manual Tests

Linked PRs

@tomekzaw tomekzaw requested a review from robertKozik February 5, 2024 19:30
@tomekzaw tomekzaw merged commit 2ed4240 into main Feb 5, 2024
@tomekzaw tomekzaw deleted the @tomekzaw/fix-android-crash branch February 5, 2024 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HOLD for payment 2024-02-14] [$500] Chat - App crashes when tapping device back button to return from thread

2 participants