pusher / pusher/pusher-websocket-react-native

NullPointerException in PusherWebsocketReactNativeModule

Open
#113 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
76
Forks
64
PR merge metrics
No merged PRs in 30d

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.

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with PusherWebsocketReactNativeModule.kt, focusing on the onAuthorizer and disconnect entry points at the reported crash lines, and compare them with the initialization flow shown in App.js. Reproduce the Android failures if possible, then verify that the reported null cases no longer cause a NullPointerException and that the resulting behavior is handled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, react-native
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.