Null pointer exception when trying to create channel #1734
Description
Bug
Hello,
While trying to create a channel the module crashed.
2020-11-05 17:30:36.355 17176-17269/com.priority_software.template E/unknown:ReactNative: Exception in native call java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference at com.dieam.reactnativepushnotification.modules.RNPushNotificationHelper.checkOrCreateChannel(RNPushNotificationHelper.java:870) at com.dieam.reactnativepushnotification.modules.RNPushNotificationHelper.createChannel(RNPushNotificationHelper.java:917) at com.dieam.reactnativepushnotification.modules.RNPushNotification.createChannel(RNPushNotification.java:306) at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) at android.os.Looper.loop(Looper.java:224) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226) at java.lang.Thread.run(Thread.java:919)
The crash is coming from this bit of code
if ( channel == null && channel_name != null && channel_description != null || channel != null && ( channel_name != null && !channel.getName().equals(channel_name) || channel_description != null && !channel.getDescription().equals(channel_description) ) )
I locally changed the condition to this, which fixed the bug:
`
if (
(channel == null && channel_name != null && channel_description != null) ||
(channel != null && channel.getName() == null || channel.getDescription() == null) ||
(channel != null &&
(
channel_name != null && !channel.getName().equals(channel_name) ||
channel_description != null && !channel.getDescription().equals(channel_description)
)
)
)
`
If you think this is a good fix, I can make a pr
In my case, for some reason channel description was null, name wasn't.
Environment info
AndroidManifest.xml:
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/azure"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="My Channel"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="My Channel Description"/>`
`
react-native info
output:
System:
OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
CPU: (4) x64 Intel(R) Core(TM) i7-4510U CPU @ 2.00GHz
Memory: 302.14 MB / 15.57 GB
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 12.18.2 - ~/.nvm/versions/node/v12.18.2/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v12.18.2/bin/npm
Watchman: Not Found
SDKs:
Android SDK:
API Levels: 28, 29, 30
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.1
System Images: android-28 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: 14.0.1 - /usr/bin/javac
Python: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.2 => 0.63.2
npmGlobalPackages:
react-native: Not Found
Library version: "react-native-push-notification": "^6.1.2",
Steps To Reproduce
Install the module on android. When starting the app call
PushNotification.createChannel({ channelId: NotificationsChannel, channelName: 'My Channel', importance: 5, });
Describe what you expected to happen:
Channel would be created