react-native-notifications icon indicating copy to clipboard operation
react-native-notifications copied to clipboard

Android 11 and above crashing on notification open

Open MajkellVZ opened this issue 4 years ago • 34 comments

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

MajkellVZ avatar Mar 08 '22 11:03 MajkellVZ

same here. Anyone already fixed this issue ?

StefanLuecke avatar Mar 09 '22 13:03 StefanLuecke

@StefanLuecke , @MajkellVZ , please see if it's fixed in 4.2.4

DanielEliraz avatar Mar 09 '22 14:03 DanielEliraz

@DanielEliraz the error persists

MajkellVZ avatar Mar 09 '22 14:03 MajkellVZ

@DanielEliraz Seems to work for me ... will test it on multiple devices tomorrow. Thx for your awesome work!

StefanLuecke avatar Mar 09 '22 15:03 StefanLuecke

for me it works when the app is killed but not when it's in background, but so did with the last version

MajkellVZ avatar Mar 09 '22 16:03 MajkellVZ

lowered the targetSkdVersion to 30 and it worked

MajkellVZ avatar Mar 09 '22 16:03 MajkellVZ

@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

DanielEliraz avatar Mar 09 '22 19:03 DanielEliraz

@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

can you please share your solution without the need to lower the sdk to 30?

ali-io avatar Mar 11 '22 11:03 ali-io

@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.

taranda avatar Mar 22 '22 17:03 taranda

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)

pepf avatar Mar 23 '22 11:03 pepf

The only solution I found was to roll back to SDK 30.

taranda avatar Mar 23 '22 19:03 taranda

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Apr 23 '22 22:04 stale[bot]

@taranda @pepf , can you please try it with version 4.3.1?

DanielEliraz avatar Apr 24 '22 14:04 DanielEliraz

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: Screenshot 2022-04-24 at 19 57 27

Opening a push notification when the activity is already running this exception is not triggered.

pepf avatar Apr 24 '22 18:04 pepf

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)

ejunebug avatar Apr 25 '22 19:04 ejunebug

@DanielEliraz So far having the same results as @hankhester with the new 4.3.1 version

jonesaustindev avatar Apr 28 '22 15:04 jonesaustindev

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

pepf avatar Jun 09 '22 21:06 pepf

Using patch-package you can apply this patch.. it seems to have worked for me: https://gist.github.com/pepf/742d4772545400919aece5649402b9e7

Logs when reproducing: Screenshot 2022-06-10 at 11 17 17

pepf avatar Jun 10 '22 09:06 pepf

@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

artyorsh avatar Jul 06 '22 16:07 artyorsh

Why is this issue closed when the crash is still persisting?

MajkellVZ avatar Sep 02 '22 07:09 MajkellVZ