WootricSDK-Android icon indicating copy to clipboard operation
WootricSDK-Android copied to clipboard

SurveyManager's NullPointerException crash spike

Open astamato opened this issue 4 years ago • 8 comments

Hello guys;

Over the past few days (specifically past 24 hours) we noticed a spike on crashes happening in our production Android app in Firebase Analytics:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Activity com.wootric.androidsdk.objects.WootricEvent.getActivity()' on a null object reference
       at com.wootric.androidsdk.SurveyManager.showSurveyFragment(SurveyManager.java:302)
       at com.wootric.androidsdk.SurveyManager.access$000(SurveyManager.java:57)
       at com.wootric.androidsdk.SurveyManager$1.run(SurveyManager.java:291)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:230)
       at android.app.ActivityThread.main(ActivityThread.java:7762)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)

Taking a look at the code, we see that currentEvent is already null at this point (either because or a previous NullPointerException trying to run they survey, or the process called stop()) and because this line is not inside the try-catch in showSurveyFragment() for NullPointerException, it crashes.

Can easily be resolved surrounding this two lines with the try-catch.

However it will maybe require further investigation down the line. Patching it this way might be hiding a bigger issue, an illegal state on the code that shouldn't have come to this.

We're on Wootric SDK version 2.18.1.

Hope this makes sense.

Thank you!

astamato avatar Feb 22 '21 10:02 astamato