IndexOutOfBoundException when receiving Google Native Ads without images



A crash surfaced after we integrated Google Native Ads Advanced recently.

Fatal Exception: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
       at java.util.ArrayList.get(
       at com.mopub.nativeads.GooglePlayServicesNative$GooglePlayServicesNativeAd.isValidContentAd(Unknown Source)
       at com.mopub.nativeads.GooglePlayServicesNative$GooglePlayServicesNativeAd.access$400(Unknown Source)
       at com.mopub.nativeads.GooglePlayServicesNative$GooglePlayServicesNativeAd$3.onContentAdLoaded(Unknown Source)

Based on the information on Google’s page:
Images seems to be a recommended field only.

We believed there are chances that Google serves native ads without any image as an empty ArrayList which leads to this crash.



Hi @david_cheng,

Thanks for reaching out. Do you have the unobfuscated stack trace so we can see the line numbers that the app is crashing on? Also, are you mediating AdMob native ads or DFP native ads? AdMob native ads should always be returned with at least one image asset.

We do have a fix in place that we plan to incorporate. It should be deployed with the adapter with the next MoPub SDK release. Stay tuned!


Hi @chauduyphanvu,

In fact we later realized someone had already filed a pull request which resolved exactly the same issue we are encountering.

We are mediating Admob native advanced, but the crash did hit quite a significant share of our users.



Got it - thanks! We will be merging this change internally and evaluating it. It should be deployed with the next release of the MoPub SDK.