AppLovin / AppLovin-MAX-Cordova

MIT License
10 stars 12 forks source link

Android NullPointerException reports from play store #43

Closed yohan-pannet-bbo closed 5 months ago

yohan-pannet-bbo commented 5 months ago

MAX Plugin Version

1.1.2

Cordova Version

12

Device/Platform Info

many devices

Current Behavior

From Android play store crash report, here is the stack trace of the error

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success()' on a null object reference at com.applovin.cordova.AppLovinMAX.lambda$showAdView$4$AppLovinMAX (AppLovinMAX.java:997) at com.applovin.cordova.-$$Lambda$AppLovinMAX$Mko6byzlR2KjXtQA0CkRpxAY-RA.run at android.app.Activity.runOnUiThread (Activity.java:7201) at com.applovin.cordova.AppLovinMAX.showAdView (AppLovinMAX.java:980) at com.applovin.cordova.AppLovinMAX.lambda$createAdView$1$AppLovinMAX (AppLovinMAX.java:926) at com.applovin.cordova.-$$Lambda$AppLovinMAX$PTG6LauycdJocU30dK4gPxRc5XU.run at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:236) at android.app.ActivityThread.main (ActivityThread.java:8056) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:656) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:967)

Expected Behavior

No response

How to Reproduce

I don't know how to reproduce, i just see the reports (quite frequent)

Additional Info

When ready the code, the error occurs when showAdView is called by createAdView (here). The 3rd argument (callbackContext) is null. In showAdView, callbackContext.success() is called causing the NPE.

My guess would be to test if callbackContext is not null before trying to call success(), and do nothing otherwise. Not sure that it make sense...

thomasmso commented 5 months ago

This is very interesting, I'm not sure how callbackContext can be null. If you can reproduce it, that would be great. Otherwise, it is perhaps an edge case bug with Cordova itself, and the appropriate action to take is to put in null-checks.

Our engineering pipeline is quite stacked at the moment, but we can release a new plugin closer to EoY.

yohan-pannet-bbo commented 5 months ago

For callbackContext to be null, here's the explanation: method signature: private void showAdView(final String adUnitId, final MaxAdFormat adFormat, final CallbackContext callbackContext) method call: showAdView( adUnitId, adFormat, null );

Here showAdView is call inside createAdView which has a 'callbackContext' which is used at the end of createAdView. In a sense, callbackContext is not null, it it just not passed to showAdView.

I'm not pushing a PR because i don't know enough the global logic. The naive fix would be to check that callbackContext is not null in showAdView before calling .success()...

thomasmso commented 5 months ago

I think you solved it! And the reason for why callbackContext will be passed as null is:

 // The publisher may have requested to show the banner before it was created. Now that the banner is created, show it.

I made a PR here: https://github.com/AppLovin/AppLovin-MAX-Cordova/pull/46

thomasmso commented 5 months ago

Plugin v1.1.3 with the fix is released: https://github.com/AppLovin/AppLovin-MAX-Cordova/releases/tag/release_1_1_3

Let me know if you need help with anything else, and thanks again for reporting this issue.

yohan-pannet-bbo commented 5 months ago

Great, thanks i'll deploy a new version of our app with this 1.1.3. We have a slow process to deploy apps. I'll try to hurry it up and come back to confirm

yohan-pannet-bbo commented 4 months ago

Hi, I confirm, no more NPE with the plugin update. Thanks again