Skip to content

NullPointerException in FlutterView#send (Android) #13481

@amirh

Description

@amirh

I'm seeing this pretty frequently in the wild in a pet project app.

I believe what happens is that a firebase realtime db data update tries to update the Dart code over the method channel right after mNativeView has been set to null.

I can repro this 100% in my app by using multi-window on Android, updating a realtime database node that I'm listening to, and immediately leave the Flutter app's Android window.
E.g have both the Flutter app and Chrome opened in 2 windows, tap a button in the Flutter app that will trigger a data change (to a node that has a listener attached), and immediately tap the Chrome window.

Android stack trace:

12-10 10:33:54.373 23892 23892 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.view.FlutterNativeView.send(java.lang.String, java.nio.ByteBuffer, io.flutter.plugin.common.BinaryMessenger$BinaryReply)' on a null object reference
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at io.flutter.view.FlutterView.send(FlutterView.java:863)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:82)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:69)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at io.flutter.plugins.firebase.database.FirebaseDatabasePlugin$EventObserver.sendEvent(FirebaseDatabasePlugin.java:177)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at io.flutter.plugins.firebase.database.FirebaseDatabasePlugin$EventObserver.onChildAdded(FirebaseDatabasePlugin.java:186)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at com.google.android.gms.internal.zzebh.zza(Unknown Source:33)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at com.google.android.gms.internal.zzegl.zzbwe(Unknown Source:2)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at com.google.android.gms.internal.zzegr.run(Unknown Source:64)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at android.os.Handler.handleCallback(Handler.java:790)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:99)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at android.os.Looper.loop(Looper.java:164)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:6494)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at java.lang.reflect.Method.invoke(Native Method)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
12-10 10:33:54.373 23892 23892 E AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Flutter Doctor

$ flutter doctor
[✓] Flutter (on Mac OS X 10.13.1 17B1003, locale en-US, channel alpha)
    • Flutter at /Users/amir/github/flutter
    • Framework revision d957c8f040 (10 days ago), 2017-11-30 13:29:59 -0800
    • Engine revision 77d8acb9be
    • Tools Dart version 1.25.0-dev.11.0
    • Engine Dart version 2.0.0-dev.9.0

[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3)
    • Android SDK at /Users/amir/Library/Android/sdk
    • Unable to locate Android NDK.
      
    • Unable to locate compiler in Android NDK.
      
    • Platform android-26, build-tools 25.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b05)

[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.2, Build version 9C40b
    • ios-deploy 1.9.2
    • CocoaPods version 1.3.1

[✓] Android Studio (version 2.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b05)

[✓] IntelliJ IDEA Community Edition (version 2017.2.5)
    • Flutter plugin version 18.1
    • Dart plugin version 172.4155.35

[✓] Connected devices
    • iPhone 7 • 06479737-2F34-4674-94E5-C235BEECE75E • ios • iOS 11.2 (simulator)

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: crashStack traces logged to the consolep: firebaseFirebase plugins

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions