Handling empty purchases list on purchase update#63
Handling empty purchases list on purchase update#63dogramacigokhan wants to merge 1 commit intogoogle:masterfrom
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
@googlebot I signed it! |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
Closing because of cla issues. For the correct PR, see: #64 |
Issue Description
Fixing payment issue while the app is running in background throws
NullReferenceException.Underlying Reason
Fixing the payment issue triggers a new purchase update from native side with null purchases list when the application is running in background, but the C# side doesn't handle this situation well and throws a
NullReferenceException. Actual underlying reason might be triggering the purchase update with null purchases list for this specific case, but considering the annotations in the native code and XML documentations in the C# code, having a null purchases list looks like a valid case and should be handled nonetheless.Fix
Fix contains three main modifications:
Fix calling a method (
size()) on a nullable list coming from native sideIn
GooglePlayBilling.aar,PurchasesUpdatedListener.onPurchasesUpdated()callback declares a nullable purchases list as follows when it's decompiled:but in
JniUtils.ParseJavaPurchaseList(), there's no null check before calling the nativesize()method on it, hence it throwsNullReferenceException.Fix handling empty purchases list
JniUtils.ParseJavaPurchaseList()has following XML doc for the return value:but
GooglePlayStoreImpl.ParsePurchaseResult()callsFirst()on the list, hence it throwsInvalidOperationExceptionwhen the list is empty.Fix enumerating
IEnumerablemultiple timesGooglePlayStoreImpl.ParsePurchaseResult()enumeratesIEnumerablepurchases list multiple times (first with_inventory.UpdatePurchaseInventory()call and then withpurchasesList.First()call). AddedToList()to evaluate it once and enumerate it multiple times safely.Related issue: https://issuetracker.google.com/issues/171860953