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

Null pointer exception when trying to create channel #1734

Closed
iamjon opened this issue Nov 5, 2020 · 6 comments
Closed

Null pointer exception when trying to create channel #1734

iamjon opened this issue Nov 5, 2020 · 6 comments

Comments

@iamjon
Copy link

iamjon commented Nov 5, 2020

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

@FelipeLimaDeSouza
Copy link

FelipeLimaDeSouza commented Nov 6, 2020

It solved for me

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="channel_id" />
<meta-data android:name="com.dieam.reactnativepushnotification.default_notification_channel_id" android:value="channel_id" />

@howg0924
Copy link

howg0924 commented Nov 9, 2020

I encountered the same issue as @iamjon.

In my case, this is because other push notification library may set empty channel description as null. When I migrated to this library and created the same channel again, the code crashed at channel.getDescription().equals(channel_description) due to channel.getDescription() is null.

@Dallas62
Copy link
Collaborator

Dallas62 commented Nov 9, 2020

Hi @iamjon,

Thanks for the report, sorry for the delay, got an issue with my mail provider...
I will look to make a fix in the next hour.

Regards

@atrofimenko
Copy link

atrofimenko commented Nov 11, 2020

Hello, guys!
I faced with the same issue, and it's reproducing when i'm trying to install new version of apk, where i added this library over previous version of the app, where this package wasn't used. Need your help!
This exceptions looks like:

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:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:764)

@atrofimenko
Copy link

I think i found a solution, added all the default values for channels in manifest and now it's ok

@Dallas62
Copy link
Collaborator

This issue should be fixed in 6.1.3,
Feel free to reopen if it's not the case.

Regards,

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

No branches or pull requests

5 participants