Android 11 and above crashing on notification open
The app crashes while opening the notification and shows the following message
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.clone()' on a null object reference
currently using version 4.2.3
same here. Anyone already fixed this issue ?
@StefanLuecke , @MajkellVZ , please see if it's fixed in 4.2.4
@DanielEliraz the error persists
@DanielEliraz Seems to work for me ... will test it on multiple devices tomorrow. Thx for your awesome work!
for me it works when the app is killed but not when it's in background, but so did with the last version
lowered the targetSkdVersion to 30 and it worked
@MajkellVZ Need to find a way to solve it also in targetSkdVersion > 30. In my app I added the logic in the MainActivity but it seems hucky. But for now ReactNative's targetSkdVersion is 30 so there is time to think
@MajkellVZ Need to find a way to solve it also in
targetSkdVersion > 30. In my app I added the logic in the MainActivity but it seemshucky. But for now ReactNative's targetSkdVersion is 30 so there is time to think
can you please share your solution without the need to lower the sdk to 30?
@DanielEliraz This problem persists for me in 4.2.4 with Android 12 and target SDK 31. I recommend keeping the issue open until this package works with > 30.
Same for our app running on Android 12 devices with targetSDKVersion set to 31 (considering turning it back to 30 now 😅 )
Versions:
"react-native-notifications": "^4.2.4",
"react-native": "0.67.2",
Sample stack trace. From the 100+ reports I can see it only happens at getInitialNotification calls from "cold boots", if the app is already running it seems to open fine:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.clone()' on a null object reference
at com.wix.reactnativenotifications.core.notification.PushNotificationProps.asBundle(PushNotificationProps.java:26)
at com.wix.reactnativenotifications.RNNotificationsModule.getInitialNotification(RNNotificationsModule.java:92)
at java.lang.reflect.Method.invoke(Method.java)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:920)
The only solution I found was to roll back to SDK 30.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
@taranda @pepf , can you please try it with version 4.3.1?
Checked latest version on an android (12) emulator with targetSdkVersion = 31 set the app build.
No crash! 🙏
Upon inspecting the adb logs, opening a push notification as a cold boot (no activity) triggers the exception:

Opening a push notification when the activity is already running this exception is not triggered.
Hmm, @DanielEliraz I'm still experiencing this on 4.3.1 when opening a push notification as a cold boot with targetSdkVersion = 31 and Android API level both 30 and 32. react-native v0.68.0
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.clone()' on a null object reference
at com.wix.reactnativenotifications.core.notification.PushNotificationProps.asBundle(PushNotificationProps.java:26)
at com.wix.reactnativenotifications.core.notification.PushNotification.notifyOpenedToJS(PushNotification.java:210)
at com.wix.reactnativenotifications.core.notification.PushNotification.dispatchImmediately(PushNotification.java:127)
at com.wix.reactnativenotifications.core.notification.PushNotification$1.onAppVisible(PushNotification.java:36)
at com.wix.reactnativenotifications.core.ReactAppLifecycleFacade.switchToVisible(ReactAppLifecycleFacade.java:88)
at com.wix.reactnativenotifications.core.ReactAppLifecycleFacade.access$000(ReactAppLifecycleFacade.java:14)
at com.wix.reactnativenotifications.core.ReactAppLifecycleFacade$1.onHostResume(ReactAppLifecycleFacade.java:27)
at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:263)
at com.facebook.react.ReactInstanceManager.moveToResumedLifecycleState(ReactInstanceManager.java:784)
at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:682)
at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:632)
at com.facebook.react.ReactDelegate.onHostResume(ReactDelegate.java:53)
at com.facebook.react.ReactActivityDelegate.onResume(ReactActivityDelegate.java:100)
at com.facebook.react.ReactActivity.onResume(ReactActivity.java:58)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1456)
at android.app.Activity.performResume(Activity.java:8129)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4434)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4476)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
@DanielEliraz So far having the same results as @hankhester with the new 4.3.1 version
After some monitoring I have to retract my earlier statement that this was fixed, I encounter crashes with the similar stack trace as @hankhester reported here.
So, @DanielEliraz just to prevent these unhandled crashes, would it be possible to patch the`notifiyOpenedToJS method to include a try...catch statement? From: https://github.com/wix/react-native-notifications/blob/a18a593e3a62f7a0d1e8f6bfae354f4af2b4c669/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java#L208-L213
to
private void notifyOpenedToJS() {
Bundle response = new Bundle();
try {
response.putBundle("notification", mNotificationProps.asBundle());
} catch (NullPointerException e) {
Log.e(LOGTAG, "notifyOpenedToJS: Null pointer exception");
}
Just like you did in #835? https://github.com/wix/react-native-notifications/blob/f7928d4e7134410e798a15fa827b9d7b047e24f5/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java#L81
Using patch-package you can apply this patch.. it seems to have worked for me: https://gist.github.com/pepf/742d4772545400919aece5649402b9e7
Logs when reproducing:

@DanielEliraz the issue still exist in v4.3.1 unfortunately. We were that unlucky project who sent ~1k push notifications to users and got ~200 crash reports same day
Android 11 and above | RN 0.68.2 | Logs
Why is this issue closed when the crash is still persisting?