-
Notifications
You must be signed in to change notification settings - Fork 61
Description
I have observed NullPointerException in PusherWebsocketReactNativeModule
multiple times on Android devices. This is mainly happening with PusherWebsocketReactNativeModule.onAuthorizer
and PusherWebsocketReactNativeModule.disconnect
. Please find the log mentioned below.
Fatal Exception: java.lang.NullPointerException:
at com.pusherwebsocketreactnative.PusherWebsocketReactNativeModule.onAuthorizer(PusherWebsocketReactNativeModule.kt:158)
at java.lang.reflect.Method.invoke(Method.java)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
at com.facebook.jni.NativeRunnable.run(NativeRunnable.java)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:1012)
and
Fatal Exception: java.lang.NullPointerException:
at com.pusherwebsocketreactnative.PusherWebsocketReactNativeModule.disconnect(PusherWebsocketReactNativeModule.kt:90)
at java.lang.reflect.Method.invoke(Method.java)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
at com.facebook.jni.NativeRunnable.run(NativeRunnable.java)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:920)
This is how I've initialized the Pusher instance in my App.js and I'm using "@pusher/pusher-websocket-react-native": "^1.2.2"
try {
if (!pusherInitedRef.current) {
await pusher.init({
apiKey: getPusherApiKey(),
cluster: getPusherCluster(),
onAuthorizer,
onError,
onEvent,
onConnectionStateChange,
onSubscriptionError,
onSubscriptionSucceeded,
});
pusherInitedRef.current = true
await pusher.connect();
}
let channel = getPrivateChannelName()
await pusher.subscribe({ channelName: channel });
setPusherConnected(true);
} catch (e) {
console.log('Pusher ERROR occured during initialization: ' + e);
}
Also, I checked the generated Kotlin file for the PusherWebsocketReactNativeModule.kt
. I can see the crash mainly happening in places where !!
is used.
It would be great if we replaced the .!!
with the .?
operator or any better null handling (or custom Exception) here. so despite what configuration we've added at least it will not throw NullPointerException
.