googleads-mobile-flutter: NullPointerException for `intValue()`

Plugin Version

2.1.0

Steps to Reproduce

It cannot be reproduced very easily and just occurs for some users of my app. Hoping that the error message itself could lead to a solution. Some implicit cast into int must be incorrect for an argument.

Expected results: No crashes

Actual results: The app crashes regularly for many users with

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
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.GoogleMobileAdsPlugin.onMethodCall(GoogleMobileAdsPlugin.java:26)
	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:2)
	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:2)
	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:2)
	at io.flutter.embedding.engine.dart.DartMessenger.a(Unknown Source:0)
	at io.flutter.embedding.engine.dart.a.run(Unknown Source:12)
	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:8025)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
). Error thrown null.
[✓] Flutter (Channel stable, 3.3.3, on macOS 12.6 21G115 darwin-arm, locale en-DE)
    • Flutter version 3.3.3 on channel stable at /Users/X/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18a827f393 (3 weeks ago), 2022-09-28 10:03:14 -0700
    • Engine revision 5c984c26eb
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/X/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/X/Library/Android/sdk
    • Java binary at: /Users/X/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/X/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.3)
    • IntelliJ at /Users/X/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 12.6 21G115 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 106.0.5249.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 12
  • Comments: 33

Most upvoted comments

Got the exact error trace with thousands of crashes…

@huycozy Screenshot 2023-05-16 001701

Closing this issue as the fix has been addressed in https://github.com/googleads/googleads-mobile-flutter/pull/967. In the short term you can use

google_mobile_ads:
  git:
    url: https://github.com/googleads/googleads-mobile-flutter
    path: packages/google_mobile_ads

to see the recent changes. This will also be included in the next release (coming this month).

Alternatively, you could modify the create() method to handle the case where the Integer object is null:

public static void create(@Nullable Integer intValue) {
  if (intValue == null) {
    // handle the case where intValue is null
  } else {
    // use intValue here
  }
}

Following for updates as looking for any alternatives/solutions to this issue. Thank you!