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

Android Crash: java.lang.IndexOutOfBoundsException #47

Closed
SkaterDad opened this issue Sep 21, 2021 · 5 comments · Fixed by #58
Closed

Android Crash: java.lang.IndexOutOfBoundsException #47

SkaterDad opened this issue Sep 21, 2021 · 5 comments · Fixed by #58

Comments

@SkaterDad
Copy link
Contributor

SkaterDad commented Sep 21, 2021

I've seen this crash recently in the Play Console. Only 12 occurrences and 10 users, thankfully.

Devices are a mix of random Chinese phones & low end Samsung & Nokia. Android 8.1, 9, 10, 11.

All of these crashes occurred on the Instant release, so maybe it's something Google screwed up in their wrapping code.

java.lang.IndexOutOfBoundsException: 
  at java.util.ArrayList.get (ArrayList.java:437)
  at com.defold.iap.IapGooglePlay$5.onSkuDetailsResponse (IapGooglePlay.java:343)
  at com.defold.iap.IapGooglePlay$6.onSkuDetailsResponse (IapGooglePlay.java:376)
  at com.android.billingclient.api.zzj.run
  at android.os.Handler.handleCallback (Handler.java:888)
  at android.os.Handler.dispatchMessage (Handler.java:100)
  at android.os.Looper.loop (Looper.java:213)
  at android.app.ActivityThread.main (ActivityThread.java:8178)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:513)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1101)

The issue seems to be here:
https://github.com/defold/extension-iap/blob/master/extension-iap/src/java/com/defold/iap/IapGooglePlay.java#L343-L344

Kind of odd that Get(0) would fail after the if statement does null & empty checks.

@britzl
Copy link
Collaborator

britzl commented Sep 21, 2021

Interesting. I wouldn't think that could happen.... One things to try is to make a copy of the skuDetailsList to ensure that no one else is messing with it from another thread or something, but it seems like a very unlikely thing to happen.

Very wild guess but it could be someone hacking your game...

@SkaterDad
Copy link
Contributor Author

Very wild guess but it could be someone hacking your game...

I suppose that is possible. It's less than 0.01% of the players, so perhaps it's not worth investigating this any further.

This just happened to be the one crash which had a useful stack trace.

@britzl
Copy link
Collaborator

britzl commented Sep 21, 2021

It might be worth looking into still! My recommendation of copying the list before checking size and getting the first item should be a quick way of ensuring that nothing is tampering with the list in between those two lines of code.

@JCash
Copy link
Contributor

JCash commented Sep 21, 2021

a quick way of ensuring that nothing is tampering with the list in between those two lines of code.

If that's the issue, then that might just as well happen while you're copying the data, right?
Which would produce similarly strange results?

Is there a recommended way of doing this? E.g. is there an example app from Google which we could adopt best practices from? Perhaps we're using an old recommended way?

@britzl
Copy link
Collaborator

britzl commented Sep 21, 2021

If that's the issue, then that might just as well happen while you're copying the data, right?
Which would produce similarly strange results?

Is there a recommended way of doing this? E.g. is there an example app from Google which we could adopt best practices from? Perhaps we're using an old recommended way?

Good point! Here's the official example from Google:

https://github.com/android/play-billing-samples/blob/main/TrivialDriveJava/app/src/main/java/com/sample/android/trivialdrivesample/billing/BillingDataSource.java#L363-L382

Things to note: We only care about the first result, hence the get(0). BUT maybe we should use a for (SkuDetails skuDetails : skuDetailsList) and use the first skuDetails instead? It doesn't really solve anything though... (except not throw a IndexOutOfBoundsException)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants