RevenueCat/purchases-android

java.lang.NullPointerException: key must not be null com.revenuecat.purchases.common.caching.DeviceCache.cleanupOldAttributionData(DeviceCache.kt:165)

AntonioCappiello opened this issue · 6 comments

java.lang.NullPointerException: key must not be null
com.revenuecat.purchases.common.caching.DeviceCache.cleanupOldAttributionData(DeviceCache.kt:165)
com.revenuecat.purchases.identity.IdentityManager.configure(IdentityManager.kt:41)
com.revenuecat.purchases.Purchases.(Purchases.kt:160)
com.revenuecat.purchases.Purchases.(Purchases.kt:94)
com.revenuecat.purchases.PurchasesFactory.createPurchases(PurchasesFactory.kt:88)
com.revenuecat.purchases.Purchases$Companion.configure(Purchases.kt:2065)
com.revenuecat.purchases.Purchases.configure(Purchases.kt:2)

A simple null check should fix this issue, i.e.:

@Synchronized
fun cleanupOldAttributionData() {
    val editor = preferences.edit()
    for (key in preferences.all.keys) {
        if (key != null && key.startsWith(attributionCacheKey)) {
            editor.remove(key)
        }
    }
    editor.apply()
}

Can you please add this to the next release?
I have paying users who cannot open the app anymore because the app crash on startup due to this issue.

👀 SDKONCALL-205 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

Hey @AntonioCappiello! Just providing an update here from what we talked about in the support ticket - the SDK team is investigating the underlying cause of the issue and will provide an update soon.

Hey @AntonioCappiello following up here:

We have a fix (#742) in place, we're going to merge and ship it very soon.

Sorry we took a bit, but we wanted to audit to try to understand why this could happen in the first place, to ensure that just doing the check wouldn't mean that we have a bug we're just living with and that patching might mean something else breaks down the road.

We couldn't really find any way to reproduce this solely within the SDK, but we did find that if SharedPreferences has a value stored with null as the key, this bug would reproduce.

Any chance this is what was happening in your case?

@AntonioCappiello that is valid feedback, thanks! We're going to look into it

This issue has been automatically locked due to no recent activity after it was closed. Please open a new issue for related reports.