Handled empty purchases list. #64
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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