Swrve / swrve-android-sdk

Swrve Android SDK
http://www.swrve.com
Other
10 stars 18 forks source link

Internal NPE when invoking `SwrveResourcesListener` #307

Closed ychescale9 closed 1 year ago

ychescale9 commented 1 year ago

Hi, we recently started using the SwrveSDK.setResourcesListener(listener) API and started getting the following crash on Firebase Crashlytics:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.swrve.sdk.SwrveResourcesListener.a()' on a null object reference
       at com.swrve.sdk.SwrveImp.lambda$invokeResourceListener$12(SwrveImp.java:1072)
       at com.swrve.sdk.SwrveImp.$r8$lambda$LGZnxH3ZDbckhNitSf92wWptxNM(SwrveImp.java)
       at com.swrve.sdk.SwrveImp$$InternalSyntheticLambda$1$26ae5ea643bad08f1eb323503441bff08b80efb0396cf4663a3513e6a1e47734$0.run(SwrveImp.java:2)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8167)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

The crash happens here

    protected void invokeResourceListener() {
        if (resourcesListener != null) {
            Activity activity = getActivityContext();
            if (activity != null) {
                activity.runOnUiThread(() -> resourcesListener.onResourcesUpdated());
            } else {
                // If we do not have access to the activity context run on current thread
                resourcesListener.onResourcesUpdated();
            }
        }
    }

It seems like the runOnUiThread lambda is capturing the resourcesListener so it might be nullable by the time the lambda is invoked in a different thread.

Please let me know if you need more info. Thanks!

fmatosqg commented 1 year ago

https://docs.swrve.com/release-notes/sdk-release-notes/android-sdk-release-notes/#Release_1091

Release 10.9.1 Release date: February 1, 2023 Fixed an issue with how the SDK called SwrveResourcesListener.onResourcesUpdated, which sometimes caused the app to crash.

dominicmarmionswrve commented 1 year ago

This is now resolved in release 10.9.1