Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when rescheduling notifications #1013

Closed
liamheneghan opened this issue Apr 24, 2018 · 2 comments
Closed

NullPointerException when rescheduling notifications #1013

liamheneghan opened this issue Apr 24, 2018 · 2 comments
Assignees

Comments

@liamheneghan
Copy link
Contributor

Issue

I have received some crash reports which originate from the notifications module of the React Native Firebase library.

After looking at the source it seemsrescheduleNotifications() (called from the boot receiver) always calls scheduleNotification(...) with a null Promise causing the exception posted below.

To replicate:

  1. Schedule a notification for some future date
  2. Reboot the Android device
Fatal Exception: java.lang.RuntimeException: Unable to start receiver io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver: java.lang.NullPointerException: Attempt to invoke interface method 'void com.facebook.react.bridge.Promise.resolve(java.lang.Object)' on a null object reference
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3194)
       at android.app.ActivityThread.-wrap17(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1672)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6501)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Caused by java.lang.NullPointerException: Attempt to invoke interface method 'void com.facebook.react.bridge.Promise.resolve(java.lang.Object)' on a null object reference
       at io.invertase.firebase.notifications.RNFirebaseNotificationManager.scheduleNotification(RNFirebaseNotificationManager.java:708)
       at io.invertase.firebase.notifications.RNFirebaseNotificationManager.rescheduleNotifications(RNFirebaseNotificationManager.java:187)
       at io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver.onReceive(RNFirebaseNotificationsRebootReceiver.java:16)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3187)
       at android.app.ActivityThread.-wrap17(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1672)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6501)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Environment

Android

  1. Application Target Platform:

Android

  1. Development Operating System:
  1. Build Tools:
  1. React Native version:

0.53.3

  1. RNFirebase Version:

4.0.3

  1. Firebase Module:

Notifications

@chrisbianca
Copy link
Contributor

Thanks for flagging - I've just pushed up a fix which will be released as part of v4.0.6 later this week

@matttti
Copy link
Contributor

matttti commented Apr 26, 2018

I also had that issue, and played around in the code last week (version 4.0.4). I discovered a follow-up bug: all scheduled notifications are fired instantly after rebooting the device, no matter of their schedule date.

Double fireDate = schedule.getDouble("fireDate"); is always 0 after reboot.

The reason is that number values created by BundleJSONConverter are parsed as Long (i guess in case they have no signs of being floating numbers)

For now, I helped myself with this patch:

     Double fireDate = schedule.getDouble("fireDate");
+    if (fireDate == 0) {
+      Long fireDateLong = schedule.getLong("fireDate");
+      fireDate = fireDateLong.doubleValue();
+    }

I cannot update to 4.0.6 at the moment. So in case this hasn't been addressed already, i hope is of help to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants