Skip to content

NPE BillingWrapper$showInAppMessagesIfNeeded$2$2.invoke #3273

@matteinn

Description

@matteinn

Describe the bug
I read #1848 and noticed you suggest to turn off in-app messages as a workaround, but what if we want that feature enabled?
Can you fix it by either adding some stronger preliminary checks before callingBillingClientImpl.showInAppMessages or try/catching it?

Here's a suggestion to be added to BillingWrapper.kt:

    val decorView = activity.window?.decorView
    if (decorView == null || decorView.windowToken == null) {
        debugLog { "Activity is not attached to a window, not showing Google Play in-app message." }
        return@withConnectedClient
    }
  1. Environment
    1. Platform: Android
    2. SDK version: 9.19.4
    3. OS version: All
    4. Android Studio version: Doesn't matter
    5. How widespread is the issue. Percentage of devices affected: < 0.1%
  2. Debug logs that reproduce the issue: Unknown
  3. Steps to reproduce, with a description of expected vs. actual behavior: Unknown
  4. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)
          Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.IBinder android.view.View.getWindowToken()' on a null object reference
       at com.android.billingclient.api.BillingClientImpl.showInAppMessages(com.android.billingclient:billing@@8.0.0:7)
       at com.revenuecat.purchases.google.BillingWrapper$showInAppMessagesIfNeeded$2$2.invoke(BillingWrapper.kt:845)
       at com.revenuecat.purchases.google.BillingWrapper$showInAppMessagesIfNeeded$2$2.invoke(BillingWrapper.kt:832)
       at com.revenuecat.purchases.google.BillingWrapper.withConnectedClient(BillingWrapper.kt:880)
       at com.revenuecat.purchases.google.BillingWrapper.access$getStackTrace(BillingWrapper.kt:88)
       at com.revenuecat.purchases.google.BillingWrapper.access$withConnectedClient(BillingWrapper.kt:88)
       at com.revenuecat.purchases.google.BillingWrapper$showInAppMessagesIfNeeded$2.invoke(BillingWrapper.kt:832)
       at com.revenuecat.purchases.google.BillingWrapper$showInAppMessagesIfNeeded$2.invoke(BillingWrapper.kt:827)
       at com.revenuecat.purchases.google.BillingWrapper.executePendingRequests$lambda$3$lambda$2$lambda$1(BillingWrapper.kt:155)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:243)
       at android.os.Looper.loop(Looper.java:338)
       at android.app.ActivityThread.main(ActivityThread.java:8531)
       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:1064)
        

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions