Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buying android.test.canceled product crashes the app #386

Closed
johnmartel opened this issue Jan 28, 2019 · 5 comments · Fixed by #510
Closed

Buying android.test.canceled product crashes the app #386

johnmartel opened this issue Jan 28, 2019 · 5 comments · Fixed by #510
Labels
🤖 android Related to android 🐛 bug Something isn't working 🚶🏻 stale Stale
Projects

Comments

@johnmartel
Copy link

johnmartel commented Jan 28, 2019

Version of react-native-iap

2.4.0-beta8

Version of react-native

0.55.4

Platforms you faced the error (IOS or Android or both?)

Android

Expected behavior

Purchase promise is rejected with E_USER_CANCELLED, "Cancelled."

Actual behavior

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)

Tested environment (Emulator? Real Device?)

Real device

Steps to reproduce the behavior

  • Purchase the Android static test product android.test.canceled
  • When 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.
@hyochan hyochan added 🐛 bug Something isn't working 🤖 android Related to android labels Jan 29, 2019
@hyochan
Copy link
Member

hyochan commented Jan 29, 2019

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.

@johnmartel
Copy link
Author

@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.

@hyochan
Copy link
Member

hyochan commented Jan 29, 2019

@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..

@martnst
Copy link

martnst commented Feb 12, 2019

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);

     // ...

@hyochan hyochan added this to Todo in Bug Mar 14, 2019
@stale
Copy link

stale bot commented May 13, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Related to android 🐛 bug Something isn't working 🚶🏻 stale Stale
Projects
Bug
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants