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

NullPointerException in PusherWebsocketReactNativeModule #113

Open
vishaledkey opened this issue Sep 20, 2023 · 3 comments
Open

NullPointerException in PusherWebsocketReactNativeModule #113

vishaledkey opened this issue Sep 20, 2023 · 3 comments

Comments

@vishaledkey
Copy link

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.

image
image

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.

@hoangtrunnam
Copy link

@vishaledkey I got the same error as you. Before I build the release, I add try catch exception to that code. So the app will not crash but will no longer be able to use realtime pusher. Both Android and ios get this error

@benw-pusher
Copy link
Contributor

Do you receive the same error on the latest version? We made some changes to improve behaviour in this area.

@NavaceSystem
Copy link

NavaceSystem commented May 30, 2024

Experiencing the same, crashing only when disconnecting on bot iOS and Android. Everything else is working great.

We're on RN 0.74.1.
Tried latest version 1.3.1 and 1.3.0 but same.

It's always this error:

Crashed::  Dispatch queue: com.facebook.react.PusherWebsocketReactNativeQueue

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

4 participants