2.4.0-beta8
0.55.4
Android
Purchase promise is rejected with E_USER_CANCELLED, "Cancelled."
App crashes:
01-28 11:21:58.177 2773-2919/ D/RNIapModule: buyItemByType (type: inapp, sku: android.test.canceled, oldSku: null, prorationMode: 0) responseCode: 0(OK)
01-28 11:22:03.509 2773-2919/ D/RNIapModule: Purchase Updated Listener
01-28 11:22:03.509 2773-2919/ D/RNIapModule: responseCode: 0
--------- beginning of crash
01-28 11:22:03.510 2773-2919/ E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: , PID: 2773
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
at com.dooboolab.RNIap.RNIapModule$11.onPurchasesUpdated(RNIapModule.java:436)
at com.android.billingclient.api.BillingClientImpl$1.onReceiveResult(BillingClientImpl.java:151)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:50)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:764)
Real device
android.test.canceled
onPurchasesUpdated
is invoked, a NPE is thrown at line 436 Purchase purchase = purchases.get(0);
because purchases
is @Nullable
and null
while responseCode
is 0.Thanks for the issue with the solution. @johnmartel I hope you to give us a PR
if you already know how to solve the problem.
@hyochan I am working on the issue right now, I will submit a PR as soon as I can. Problem is the lib is severely lacking tests and it is hard to be sure I am not breaking anything else.
@johnmartel Yeah. I always wish to implement some test modules but currently, I am always running out of time 😿. We'll have to check on runtime ourselves before releasing..
How about just checking if the purchases
are null
like so?
PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
Log.d(TAG, "Purchase Updated Listener");
Log.d(TAG, "responseCode: " + responseCode);
if (responseCode != BillingClient.BillingResponse.OK) {
rejectPromisesWithBillingError(PROMISE_BUY_ITEM, responseCode);
return;
}
+ if (purchases == null) {
+ rejectPromisesWithBillingError(PROMISE_BUY_ITEM , responseCode);
+ return;
+ }
Purchase purchase = purchases.get(0);
// ...
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.
Most helpful comment
@johnmartel Yeah. I always wish to implement some test modules but currently, I am always running out of time 😿. We'll have to check on runtime ourselves before releasing..