Android Oreo or higher, calling a deleteChannelGroup() on a channelGroupId that is not known to the system causes a NPE that results in an app crash.
I'm calling this on initialization to get a "clean slate". Firebase doesn't provide a way to know what channels & groups currently exist, and rather than store them. When I start the app, I look to just clean everything out (removing groups removes all associated channels), and then build back up.
Here is the crash log:
09-10 09:36:38.670 16917 16974 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
09-10 09:36:38.670 16917 16974 E AndroidRuntime: Process: com.relaygo.spectre.companion, PID: 16917
09-10 09:36:38.670 16917 16974 E AndroidRuntime: java.lang.NullPointerException: Attempt to read from field 'java.util.Map com.android.server.notification.RankingHelper$Record.groups' on a null object reference
09-10 09:36:38.670 16917 16974 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1948)
09-10 09:36:38.670 16917 16974 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1888)
09-10 09:36:38.670 16917 16974 E AndroidRuntime: at android.app.INotificationManager$Stub$Proxy.deleteNotificationChannelGroup(INotificationManager.java:1683)
09-10 09:36:38.670 16917 16974 E AndroidRuntime: at android.app.NotificationManager.deleteNotificationChannelGroup(NotificationManager.java:514)
09-10 09:36:38.670 16917 16974 E AndroidRuntime: at io.invertase.firebase.notifications.RNFirebaseNotificationManager.deleteChannelGroup(RNFirebaseNotificationManager.java:137)
09-10 09:36:38.670 16917 16974 E AndroidRuntime: at io.invertase.firebase.notifications.RNFirebaseNotifications.deleteChannelGroup(RNFirebaseNotifications.java:171)
Instead of fatal crash, I would expect the method just to eat the exception, or to surface as a promise rejection.
The point in the code that should have the NPE guard:
https://github.com/invertase/react-native-firebase/blob/master/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotifications.java#L178
Application Target Platform:
Android, Oreo or higher (that's when notification channels are supported)
React Native version:
0.55.4
React Native Firebase Version:
4.3.8
Firebase Module:
Messaging, Android Notifications, Channels & Groups
I'm happy to open a pull request against this, just let me know the desired behavior, should the NPE occur.
@ecexplorer hello again :)
A PR would be great! You should be able to call notificationManager.getNotificationChannelGroup(channelGroupId) and if it returns null then reject with:
promise.reject("notifications/channel-group-not-found", "The requested NoticationChannelGroup does not exist, have you created it?");
Something like that :)
Pull request created. And hello to you @Salakar :)
PR merged, thank you for this 馃憤