invertase / react-native-notifee

Moved to https://github.com/invertase/notifee
https://invertase.io/blog/open-sourcing-notifee
Other
466 stars 31 forks source link

Attempt to invoke virtual method 'android.content.Intent android.app.Activity.getIntent()' on a null object reference #374

Closed mars-lan closed 3 years ago

mars-lan commented 3 years ago

Seems like not only was getInitialNotification deprecated for iOS in 1.11.0 (See https://github.com/notifee/react-native-notifee/issues/372), the native Android code was also removed, which led to crashes when calling getInitialNotification.

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'android.content.Intent android.app.Activity.getIntent()' on a null object reference

app.notifee.core.Notifee.getInitialNotification (SourceFile:6)
io.invertase.notifee.NotifeeApiModule.getInitialNotification (NotifeeApiModule.java:267)
java.lang.reflect.Method.invoke (Method.java)
com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:151)
com.facebook.react.bridge.queue.NativeRunnable.run (NativeRunnable.java)
helenaford commented 3 years ago

oh no. there's wasn't any changes to getInitialNotification() except to populate it for full-screen actions. I will look into this immediately. Our e2e tests passing, this is very surprising. thanks for letting us know 🙏

mars-lan commented 3 years ago

Actually my bad. It seems that getInitialNotification is still there but it tried to invoke getIntent on a null pointer. This is a new crash since 1.11.0 though.

helenaford commented 3 years ago

@mars-lan no problem. I can see the issue, pushing up a fix but out of curiosity where in your application do you call getInitialNotification? Seems like the activity is null for some reason. Maybe it depends on where in the app it's being called before it has a chance to be created 🤔

mikehardy commented 3 years ago

In RNFB we have checks for null activity and null intent off the activity, they are both corner cases with decreasing hit rates but both have come up with certain combos of other modules

mars-lan commented 3 years ago

@mars-lan no problem. I can see the issue, pushing up a fix but out of curiosity where in your application do you call getInitialNotification? Seems like the activity is null for some reason. Maybe it depends on where in the app it's being called before it has a chance to be created 🤔

It was invoked inside the handled for notification action press. Maybe the main activity has been killed in the background already and wasn't created by that point?

mikehardy commented 3 years ago

This is potentially a problem for correctly passing the data then right? No activity implies no intent. Because of the bridge being separate from the activity it's possible to have no current activity but there must be some way to eventually get the initial notification data. This is a real struggle in a react native context, handling these initial items

helenaford commented 3 years ago

@mars-lan pushed up a fix in v1.11.1.

@mikehardy yeah, seems very strange that it would be null. Maybe it should only be called initially and not in any event handlers 🤔 But either way, it's good to be safe and prevent it from throwing an error, I guess 😅 .