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

Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference #1096

Open
shijianan201 opened this issue May 17, 2024 · 6 comments
Labels
p2-medium platform-android Android applications specifically

Comments

@shijianan201
Copy link

Plugin Version

ad sdk: 5.1.0 flutter:3.19.1

Steps to Reproduce

firebase crashlytics record some crash throws by GoogleMobileAdsPlugin.java.

Logs
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
	at io.flutter.plugins.googlemobileads.i0.onMethodCall(GoogleMobileAdsPlugin.java:559)
	at jk.j$a.a(MethodChannel.java:18)
	at yj.c.l(DartMessenger.java:19)
	at yj.c.m(DartMessenger.java:42)
	at yj.c.i(DartMessenger.java:1)
	at yj.b.run(R8$$SyntheticClass:13)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:211)
	at android.os.Looper.loop(Looper.java:300)
	at android.app.ActivityThread.main(ActivityThread.java:8315)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:581)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1028)
)
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:651)
       at MethodChannel._invokeMethod(platform_channel.dart:334)
@malandr2
Copy link
Collaborator

Hi @shijianan201, can you provide any reproducible steps?

@malandr2 malandr2 added feedback required Further information is requested platform-android Android applications specifically labels May 28, 2024
@shijianan201
Copy link
Author

Hi @shijianan201, can you provide any reproducible steps?

It only occurs in release mode, I cannot reproduce from debug. but It appears when I upgrade sdk from 5.0.0 to 5.1.0.

@github-actions github-actions bot removed the feedback required Further information is requested label May 29, 2024
@malandr2
Copy link
Collaborator

@shijianan201 got it, I'll escalate to engineering to take a closer look. If you have any other information from Crashlytics please share to help with the debugging process. Thanks

@malandr2
Copy link
Collaborator

@shijianan201 engineering is unable to reproduce the crash. Do you have any more information you can share so we can take a closer look?

@malandr2 malandr2 added the feedback required Further information is requested label Jun 13, 2024
@shijianan201
Copy link
Author

shijianan201 commented Jun 17, 2024

@shijianan201 engineering is unable to reproduce the crash. Do you have any more information you can share so we can take a closer look?

I forked this project modify the code like below.

GoogleMobileAdsPlugin.java

public class GoogleMobileAdsPlugin implements FlutterPlugin, ActivityAware, MethodCallHandler {

   ......
    //make sure no exception throw
    public static <T> T safeArgument(MethodCall call,String key){
        try {
          return call.<T>argument(key);
        }catch (Exception e){
          return null;
        }
      }

    public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result) {
        ......
        case "setImmersiveMode":
        Integer adId = safeArgument(call,"adId");
        if(adId == null){
          result.error(NullPointerException.class.getSimpleName(),"getAdSize failed empty params",null);
        }else{
          Boolean immersiveModeEnabled = safeArgument(call,"immersiveModeEnabled");
          FlutterOverlayAd ad = ((FlutterOverlayAd) instanceManager.adForId(adId));
          if(ad != null && immersiveModeEnabled != null) {
            ad.setImmersiveMode(immersiveModeEnabled);
          }
          result.success(null);
        }
        break;
       .......
   }
   .....
}

Now firebase crashlytics record

          Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(NullPointerException, getAdSize failed empty params, null, null)
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:651)
       at MethodChannel._invokeMethod(platform_channel.dart:334)
        

Then I read the setImmersiveMode code in dart, I found no try catch block use in this function. so I think it because sometimes adId is null when setImmersiveMode function called from dart to java, then java throws exception,but dart doesn't catch it. And I think not only setImmersiveMode function produce this problem, all function in GoogleMobileAdsPlugin'onMethodCall can produce.

@github-actions github-actions bot removed the feedback required Further information is requested label Jun 17, 2024
@LTPhantom
Copy link
Collaborator

Thank you, @shijianan201. I see the issue now, it definitely needs some more handling on the dart layer. Will work on this for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-medium platform-android Android applications specifically
Projects
None yet
Development

No branches or pull requests

3 participants