question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

github_iconTop GitHub Comments

1reaction
ghostcommented, Jan 4, 2019

I have similar the problem with the billing libray 1.2 purchasesResult.purchasesList always return null. I can’t check if a user paid to restore paid state. I need to make a new purchase and check if reponseCode return ITEM_ALREADY_OWNED

billingClient = BillingClient.newBuilder(activity).setListener(this).build()
val purchasesResult = billingClient.queryPurchases(INAPP)
Timber.d("purchasesResult.responseCode -> ${purchasesResult.responseCode}")
if (purchasesResult.responseCode == OK && purchasesResult.purchasesList != null) {
      // never call even responseCode == OK
	purchasesResult.purchasesList.forEach {
		Timber.d("purchased item -> ${it.sku} - ${it.orderId}")
	}
	donateClientListener.markPurchased()
}

---------------------------------------------

fun makePurchase(skuDetails: SkuDetails): Boolean {
	val flowParams = BillingFlowParams.newBuilder()
			.setSkuDetails(skuDetails)
			.build()
	val responseCode = billingClient.launchBillingFlow(activity, flowParams)
	when (responseCode) {
		ITEM_ALREADY_OWNED -> donateClientListener.markPurchased() // user paid

		OK -> Timber.d("makePurchase() successful!")

		else -> Timber.e(DonationException("makePurchase()", responseCode))
	}

	billingClient.endConnection()

	return responseCode == OK
}
0reactions
mediavrogcommented, Feb 27, 2019

Oh and for the size issue, this is definitely a sample error since without checking the response code for OK, the logging logs

Log.i(TAG, "Querying subscriptions result code: "
                        + subscriptionResult.responseCode
                        + " res: ${subscriptionResult.purchasesList.size}")

At least for Kotlin, it should be

Log.i(TAG, "Querying subscriptions result code: "
                        + subscriptionResult.responseCode
                        + " res: ${subscriptionResult.purchasesList?.size}")

This bug will not surface if your proguard strips all logs in production

Read more comments on GitHub >

github_iconTop Results From Across the Web

subscriptionResult.getPurchasesList() may return null ... - GitHub
getPurchasesList() may return null to cause NPE #92 ... After querying purchases, the flow will enter subscription result processing, ...
Read more >
getPurchasesList Null Pointer Exception - java - Stack Overflow
returns an object where result.getPurchasesList() == null , which causes the NPE in line if(result.getPurchasesList().size() >= 0).
Read more >
Java NullPointerException - Detect, Fix, and Best Practices
The root cause is NullPointerException in the statement user.getUserId().toLowerCase() because user.getUserId() is returning null.
Read more >
Retrofitting null-safety onto Java at Meta
We developed a new static analysis tool called Nullsafe that is used at Meta to detect NullPointerException (NPE) errors in Java code.
Read more >
Null Pointer Exception In Java - GeeksforGeeks
NullPointerException is thrown when program attempts to use an object reference that has the null value. These can be: Invoking a method from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found