Billing Compatibility SDK onProductDetailsResponse returning NULL ProductDetails

I’m probably misunderstanding this, but I’m trying the Appstore Billing Compatibility SDK with my existing Google Play Kotlin code. It has a declaration on ProductDetailsResponseListener as follows:

override fun onProductDetailsResponse(billingResult: BillingResult, productDetailsList: MutableList<ProductDetails>) { }

But when I try to test, Kotlin crashes with a message:

java.lang.NullPointerException: Parameter specified as non-null is null: method com.eggheadgames.appcore.AtriumActivity.onProductDetailsResponse, parameter productDetailsList

Unfortunately I can’t test productDetailsList for null because it’s not declared as nullable - and if I try, then it’s incompatible with the compatibility library (as well as the Google library). Or so it seems …

E.g. declared as follows (adding a ? at the end):

override fun onProductDetailsResponse(billingResult: BillingResult, productDetailsList: MutableList?)

then I get an error:

Type mismatch: inferred type is MutableList<com.eggheadgames.appcore.ProductDetails /* = com.amazon.device.iap.billingclient.api.ProductDetails />? but Collection<com.eggheadgames.appcore.ProductDetails / = com.amazon.device.iap.billingclient.api.ProductDetails */> was expected

I guess the question is, can ProductDetails ever be NULL? And, if so, how can I declare that to Kotlin?

Thanks!

Ah, I see the Google declaration is:

public interface ProductDetailsResponseListener {
    void onProductDetailsResponse(@NonNull BillingResult var1, @NonNull List<ProductDetails> var2);
}

so it should never be null …

Hi there,

Thanks for posting! We have forwarded your question to the appropriate team, we will update you as soon as we have more information on this.

Hi eggheadgames,

Thank you for your patience with this issue. We got the confirmation that even though Billing Compatibility SDK strives to create similar interfaces as that of Google, but it might not be able to do so always. In this case, Product details can be null. This occurs when the SDK is unable to fetch product details from backend.

Our suggestion is to add a null check inside the method body and process the response if it is not null.

Thanks for the response. Of course this is what I have already done (wrapped the errant call).

In practice this is tedious because the interface specification says it is not null and in Kotlin it is not even possible to check for null because of this so then a wrapper is required etc etc.

To comply with this interface specification, Google instead returns an empty array.

Surely the Billing Compatibility SDK can be adjusted to also return an empty array in the scenario described? (ie “when the SDK is unable to fetch product details from backend”). This would be better than every SDK consumer having to first find this null scenario and then guard against it.

Thanks, Michael

Hi Michael,

Thanks for your feedback, I have shared your feedback with the internal team for consideration.