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

Fatal Exception: java.lang.NullPointerException #120

Open
MakChan opened this issue Aug 6, 2021 · 2 comments
Open

Fatal Exception: java.lang.NullPointerException #120

MakChan opened this issue Aug 6, 2021 · 2 comments

Comments

@MakChan
Copy link

MakChan commented Aug 6, 2021

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void zendesk.chat.ObservationScope.cancel()' on a null object reference
       at com.taskrabbit.zendesk.RNZendeskChatModule$1.update(RNZendeskChatModule.java:369)
       at com.taskrabbit.zendesk.RNZendeskChatModule$1.update(RNZendeskChatModule.java:363)
       at zendesk.chat.ObservableData.notifyObservers(ObservableData.java:175)
       at zendesk.chat.ObservableData.setData(ObservableData.java:161)
       at zendesk.chat.ZendeskChatProvider$2.update(ZendeskChatProvider.java:176)
       at zendesk.chat.ZendeskChatProvider$2.update(ZendeskChatProvider.java:173)
       at zendesk.chat.MainThreadPoster$1$1.run(MainThreadPoster.java:43)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8512)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Device:
Samsung Galaxy S20+ (SM-G985F) Android 11

Versions:
react-native 0.64.2
react-native-zendesk-chat 0.4.1

@thuynt99
Copy link

@MakChan Have any solution?

@pt7892
Copy link

pt7892 commented Oct 28, 2021

This is reproducible with following steps:

  1. start chat
  2. close pre chat form
  3. start chat again
  4. finish entering form details
  5. start chat with agent
  6. crash happens

This is happening because observeChatState is called every time startChat is called, even if chat state observer was attached before

I created this patch file react-native-zendesk-chat+0.4.1.patch as temporary solution, tested it and seems to fix the issue

diff --git a/node_modules/react-native-zendesk-chat/android/src/main/java/com/taskrabbit/zendesk/RNZendeskChatModule.java b/node_modules/react-native-zendesk-chat/android/src/main/java/com/taskrabbit/zendesk/RNZendeskChatModule.java
index 143efb9..bb2717f 100644
--- a/node_modules/react-native-zendesk-chat/android/src/main/java/com/taskrabbit/zendesk/RNZendeskChatModule.java
+++ b/node_modules/react-native-zendesk-chat/android/src/main/java/com/taskrabbit/zendesk/RNZendeskChatModule.java
@@ -358,6 +358,11 @@ public class RNZendeskChatModule extends ReactContextBaseJavaModule {
 
     // https://support.zendesk.com/hc/en-us/articles/360055343673
     public void setupChatStartObserverToSetVisitorInfo(){
+        // Stop if we already have chat state observer
+        if (observationScope != null) {
+          return;
+        }
+
         // Create a temporary observation scope until the chat is started.
         observationScope = new ObservationScope();
         Chat.INSTANCE.providers().chatProvider().observeChatState(observationScope, new Observer<ChatState>() {
@@ -366,8 +371,10 @@ public class RNZendeskChatModule extends ReactContextBaseJavaModule {
                 ChatSessionStatus chatStatus = chatState.getChatSessionStatus();
                 // Status achieved after the PreChatForm is completed
                 if (chatStatus == ChatSessionStatus.STARTED) {
-                    observationScope.cancel(); // Once the chat is started disable the observation
-                    observationScope = null; // Clean things up to avoid confusion.
+                    if (observationScope != null) {
+                        observationScope.cancel(); // Once the chat is started disable the observation
+                        observationScope = null; // Clean things up to avoid confusion.
+                    }
                     if (pendingVisitorInfo == null) { return; }
 
                     // Update the information MID chat here. All info but Department can be updated

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

3 participants