crisp-im / crisp-sdk-android

:package: Crisp Android SDK, add a chat in any Android app and communicate with your users.
https://docs.crisp.chat/guides/chatbox-sdks/android-sdk/
Other
55 stars 17 forks source link

NullPointerException TimerTask.cancel() on a null object reference #139

Closed Damien-L closed 1 year ago

Damien-L commented 1 year ago

Hi,

We just faced a new crash with Crisp SDK version 1.0.13.

HUAWEI P30 Android 10

Fatal Exception: java.lang.RuntimeException: Unable to stop activity {fr.leocare.app/im.crisp.client.ChatActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.TimerTask.cancel()' on a null object reference at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:5546) at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:5516) at android.app.ActivityThread.handleStopActivity(ActivityThread.java:5591) at android.app.servertransaction.StopActivityItem.execute(StopActivityItem.java:41) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8668) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109) Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.TimerTask.cancel()' on a null object reference at im.crisp.client.internal.f.a.$r8$lambda$7ujKoe96iT-qVleZDkaq09JM4xw(SourceFile:13) at im.crisp.client.internal.f.a.$r8$lambda$J06KrEUyW_4qxGqa69mu0wKmMpE(SourceFile:7) at im.crisp.client.internal.f.a.$r8$lambda$7F2ld0z15QU9Ef4vOP50PxdVI8U(SourceFile:51) at im.crisp.client.internal.f.b$u.a(SourceFile:2) at im.crisp.client.internal.f.a.$r8$lambda$0twJuw9WgM4yewfdsLTkXu5dkVo(SourceFile:9) at im.crisp.client.internal.f.a.$r8$lambda$0twJuw9WgM4yewfdsLTkXu5dkVo(SourceFile:1) at im.crisp.client.internal.f.b.b(SourceFile:56) at im.crisp.client.internal.t.a.onStop(SourceFile:6) at androidx.fragment.app.Fragment.performStop(Fragment.java:3325) at androidx.fragment.app.FragmentStateManager.stop(FragmentStateManager.java:639) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:299) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1424) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2968) at androidx.fragment.app.FragmentManager.dispatchStop(FragmentManager.java:2910) at androidx.fragment.app.FragmentController.dispatchStop(FragmentController.java:307) at androidx.fragment.app.FragmentActivity.onStop(FragmentActivity.java:374) at androidx.appcompat.app.AppCompatActivity.onStop(AppCompatActivity.java:254) at im.crisp.client.ChatActivity.onStop(SourceFile:7) at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1494) at android.app.Activity.performStop(Activity.java:8447) at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:5538) at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:5516) at android.app.ActivityThread.handleStopActivity(ActivityThread.java:5591) at android.app.servertransaction.StopActivityItem.execute(StopActivityItem.java:41) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8668) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

Doc1faux commented 1 year ago

Hi @Damien-L and thank you for your feedback.

I have just symbolicated the stacktrace you have provided but what is strange is there is a null check just the line before... Is the crash happens often? Do you have a reproductible case?

Damien-L commented 1 year ago

I updated the issue with the full stacktrace. But maybe it doesn't help more.

We had this issue only one time on production environment. I don't know if it's specific to HUAWEI P30 on Android 10 or not. We're not able to reproduce.

Doc1faux commented 1 year ago

Indeed, it does not help much more :/

I had also this exception once on the brand new beta app but I have no clue for the moment how this could happen... Maybe with a race condition between 2 threads (we are using our owns to split our app logic) if Socket.IO are using their own thread to publish socket messages which we react to. I will dive into this explanation...

Doc1faux commented 1 year ago

I confirm that Socket.IO uses its own thread for sending/receiving messages (just tested now). So when a message is received on the socket it is dispatched through their thread. I updated the SDK to be thread-safe upon message reception which should fix this crash.

It will be available in the next 1.0.14 release. I will let you know when it will be published ;)

Doc1faux commented 1 year ago

@Damien-L 1.0.14 fixing this issue has just been released. It can take a few hours before it will be available. I close the issue.