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

NullPointerException when notifications are received on Android #1387

Closed
coolnalu opened this issue Nov 14, 2021 · 6 comments · Fixed by #1388
Closed

NullPointerException when notifications are received on Android #1387

coolnalu opened this issue Nov 14, 2021 · 6 comments · Fixed by #1388

Comments

@coolnalu
Copy link

Describe the bug
Whenever the app receives a notification, the app crashes and the follow error is printed in the console.

Debug service listening on ws://127.0.0.1:64921/GHAS9AWbqC8=/ws
Syncing files to device Pixel 4...
D/CompatibilityChangeReporter( 5081): Compat change id reported: 160794467; UID 10601; state: DISABLED
D/AndroidRuntime( 5081): Shutting down VM
E/AndroidRuntime( 5081): FATAL EXCEPTION: main
E/AndroidRuntime( 5081): Process: com.dexterous.flutter_local_notifications_example, PID: 5081
E/AndroidRuntime( 5081): java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.success(java.lang.Object)' on a null object reference
E/AndroidRuntime( 5081): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin$2$1.run(FlutterLocalNotificationsPlugin.java:371)
E/AndroidRuntime( 5081): 	at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime( 5081): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 5081): 	at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime( 5081): 	at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime( 5081): 	at android.app.ActivityThread.main(ActivityThread.java:7838)
E/AndroidRuntime( 5081): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5081): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime( 5081): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I/Process ( 5081): Sending signal. PID: 5081 SIG: 9
Lost connection to device.

To Reproduce

  1. Clone flutter_local_notifications
  2. Open the example project in Android Studio
  3. Launch the example app and click on 'Schedule notification to appear in 5 seconds'
  4. Background the app
  5. 5 seconds later, when the notification arrives, got the error above

Expected behavior
It should not crash

Sample code to reproduce the problem
The issue is replicated in the example app

Flutter doctor result

[✓] Flutter (Channel stable, 2.5.1, on macOS 11.6 20G165 darwin-arm, locale en-US)
    • Flutter version 2.5.1 at /Users/txu/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffb2ecea52 (8 weeks ago), 2021-09-17 15:26:33 -0400
    • Engine revision b3af521a05
    • Dart version 2.14.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/txu/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = /Users/txu/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.1, Build version 13A1030d
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/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.10+0-b96-7249189)

[✓] VS Code (version 1.62.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.28.0

[✓] Connected device (3 available)
    • Pixel 4 (mobile) • 99161FFAZ004JM • android-arm64  • Android 12 (API 31)
    • macOS (desktop)  • macos          • darwin-arm64   • macOS 11.6 20G165 darwin-arm
    • Chrome (web)     • chrome         • web-javascript • Google Chrome 95.0.4638.69

• No issues found!
@coolnalu coolnalu changed the title NullPointerException when notification is received on Android NullPointerException when notifications are received on Android Nov 14, 2021
@MaikuB
Copy link
Owner

MaikuB commented Nov 14, 2021

Thanks for reporting this. Not sure why this didn't appear when I was previously testing. Will release a new version with the fix soon

@MaikuB
Copy link
Owner

MaikuB commented Nov 14, 2021

I've published 9.1.2 that should fix this issue. Could you give this a spin and let me know how it goes?

@coolnalu
Copy link
Author

Hey @MaikuB Just tested the new version. Didn't crash. I think it's fixed! Thanks for the quick PR and the awesome work!

@mk-dev-1
Copy link

Good Morning,

it may or may not be related, but even after upgrading to 9.1.2 I am getting the occasional error below reported under the same name/issue in Crashlytics:

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver: java.util.concurrent.RejectedExecutionException: Task com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin$b@ceef8ec rejected from java.util.concurrent.ThreadPoolExecutor@42014b5[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:4495)
       at android.app.ActivityThread.access$1600(ActivityThread.java:301)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2177)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8633)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by java.lang.NullPointerException: Attempt to invoke interface method 'void java.util.concurrent.ExecutorService.execute(java.lang.Runnable)' on a null object reference
       at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.commitAsync(FlutterLocalNotificationsPlugin.java:7)
       at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.saveScheduledNotifications(FlutterLocalNotificationsPlugin.java:22)
       at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.saveScheduledNotification(FlutterLocalNotificationsPlugin.java:43)
       at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.scheduleNextRepeatingNotification(FlutterLocalNotificationsPlugin.java:52)
       at com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver.onReceive(ScheduledNotificationReceiver.java:100)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:4478)
       at android.app.ActivityThread.access$1500(ActivityThread.java:301)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2169)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8595)```

@MaikuB
Copy link
Owner

MaikuB commented Nov 17, 2021

@mk-dev-1 can you provide steps to reproduce that issue. I don't see how that can be possible in 9.1.2 given there are null checks in the code to prevent that from happening. Looks more like something that could've happen with 9.1.1

@mk-dev-1
Copy link

At this point I can‘t, but I have not changed anything in my implementation other than upgrading to the latest version of the plugin. At first I thought it was just errors reported late to Crashlytics and therefore being allocated to the wrong app version, but I can see the numbers slowly creeping updwards.

There is also a new issue open on this - got to decide whether to continue here or at #1397

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