Flutterfire: [firebase_auth] [production] NullPointerException: Attempt to invoke virtual method 'void e.b.b.a.j.a(java.lang.String, java.lang.Object)' on a null object reference

Created on 27 Apr 2020  ยท  19Comments  ยท  Source: FirebaseExtended/flutterfire

Describe the bug
When logging in via Facebook my user reports that app crashes from time to time. I couldn't reproduce it on my device.

Bug report

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void e.b.b.a.j.a(java.lang.String, java.lang.Object)' on a null object reference
       at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin$3.onAuthStateChanged(FirebaseAuthPlugin.java:45)
       at com.google.firebase.auth.zzp.run(zzp.java:24)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at com.google.android.gms.internal.firebase_auth.zzj.dispatchMessage(zzj.java)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6854)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
Device
Brand: LGE
Model: LG G7 ThinQ
Orientation: Portrait
RAM free: 516.09 MB
Disk free: 9.29 GB
Operating System
Version: 9
Orientation: Portrait
Rooted: No

Additional context
The app uses flutter_facebook_login 3.0.0 package to login via Facebook.

firebase_auth version is 0.16.0

Flutter doctor
Run flutter doctor and paste the output below:

Doctor summary (to see all details, run flutter doctor -v):
[โœ“] Flutter (Channel beta, v1.17.0-3.2.pre, on Mac OS X 10.15.4 19E287, locale pl-PL)

[โœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[โœ“] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[โœ“] Chrome - develop for the web
[โœ“] Android Studio (version 3.6)
[โœ“] VS Code (version 1.44.2)
[โœ“] Connected device (3 available)

โ€ข No issues found!
customer-response android auth needs-repro bug

Most helpful comment

Thanks a lot for this! As you mentioned this issue is similar to others in cloud_firestore and potentially other plugins. Hope to see this merged soon.

All 19 comments

Hi @orestesgaolin
thank you for reporting the crash
you may want to consider opening an issue on flutter_facebook_login as well;
also could you please provide you pubspec.yaml
thank you

Thanks for the response!

Here are my pubspec.yaml dependencies:

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  cloud_firestore: ^0.13.5
  cupertino_icons: ^0.1.3
  firebase_auth: 0.16.0
  flutter_facebook_login: ^3.0.0
  flutter_bloc: ^4.0.0
  firebase_crashlytics: ^0.1.3+3
  firebase_storage: ^3.1.5
  freezed_annotation: ^0.7.1
  google_sign_in: ^4.4.4
  json_serializable: ^3.3.0
  mock_data: ^1.2.6
  provider: ^4.0.5
  rxdart: ^0.24.0
  uuid: ^2.0.4
  flutter_hooks: ^0.9.0
  camera: ^0.5.7+4
  permission_handler: ^5.0.0+hotfix.4
  flutter_portal: ^0.0.1+2
  animations: ^1.0.0+5
  shared_preferences: ^0.5.7
  cached_network_image: ^2.1.0+1
  http: ^0.12.0+4
  intl: ^0.16.1
  path_provider: ^1.6.7
  path: ^1.6.4
  dio: ^3.0.9
  dio_http_cache: ^0.2.6
  mockito: ^4.1.1
  exif: ^1.0.2
  flutter_slidable: ^0.5.4
  keyboard_actions: ^3.2.1
  jiffy: ^3.0.1
  auto_size_text: ^2.1.0
  flutter_bugfender: ^1.1.0
  stack_trace: ^1.9.3
  package_info: ^0.4.0+17
  flutter_widget_from_html_core: ^0.4.0-rc.2020041601
  firebase_admob: 0.9.3+2
  pretty_dio_logger: ^1.1.1
  implicitly_animated_reorderable_list: ^0.1.10
  fl_chart: ^0.9.3
  tuple: ^1.0.3
  smooth_page_indicator: ^0.1.5
  flutter_svg: ^0.17.4
  firebase_analytics: ^5.0.11
  device_preview: ^0.3.0+1
  apple_sign_in: ^0.1.0

I have same issue crashing app with firebase auth on 0.16.0 version, channel stable. When downgrade to version 0.15.5+3 its working ok.
Error is onAuthchanged listener.

I have same issue crashing app with firebase auth on 0.15.5+3 version, channel stable. When downgrade to version 0.15.5+3 its working ok.

Could you write again to which version you downgraded the firebase auth plugin?

I'm getting the same error. I'm using Google, Facebook, Apple and password auth.
There's nothing in the logs to indicate which one is causing this error though.

Doctor summary (to see all details, run flutter doctor -v):
[โœ“] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale en-GB)

[โœ“] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[โœ“] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[โœ“] Android Studio (version 3.6)
[โœ“] VS Code (version 1.44.1)
[โœ“] Connected device (2 available)

โ€ข No issues found!
  firebase_auth: ^0.16.0

  google_sign_in: ^4.4.4
  flutter_facebook_login: ^3.0.0
  apple_sign_in: ^0.1.0

Could you write again to which version you downgraded the firebase auth plugin?
crash version: 0.16.0

Made a PR #2605 - I can reproduce this error 100% on my application for version 0.16.0 and if people want code to reproduce I can provide when I'm free :>.

For those willing to see if my PR fixes it for you (just cause it fixed it for me doesn't mean it fixes for everyone), you may add this to your pubspec.yaml:

  firebase_auth:
    git:
      url: [email protected]:gching/flutterfire.git
      ref: fix/auth-channel-null
      path: packages/firebase_auth/firebase_auth

It hasn't been reviewed + approved yet so I would suggest not using it in production yet :)

Quick Background

  • When the application is detached and there is at least one listener for the authentication state, the listeners aren't cleaned up and therefore will reference a channel that is null

Thanks a lot for this! As you mentioned this issue is similar to others in cloud_firestore and potentially other plugins. Hope to see this merged soon.

I am facing the same issue with version 0.16.0. Downgrading to 0.15.5+3 works fine. Pulled my hairs off to find this temporary solution. Hopefully this gets fixed soon on the latest version.

We're having the same issue. Looking forward to seeing https://github.com/FirebaseExtended/flutterfire/pull/2605 merged soon!

I am experiencing the same issue. Downgrading isn't working for me. Please provide the fix soon.

@johnvinosh Which version did you downgrade to? This error shouldn't be occurring for version 0.15.5+3

@gching I used 0.16.0. I will use 0.15.5+3. But will they have any other impact ?

Is this issue on the radar? I still see this happening across different devices
image

@gching I used 0.16.0. I will use 0.15.5+3. But will they have any other impact ?

Changing the version to 0.15.5+3 fixed the issue for me. Thanks

  • When the application is detached and there is at least one listener for the authentication state, the listeners aren't cleaned up and therefore will reference a channel that is null

I've been experiencing this crash when the conditions above have been met.
I close the app while flutter run is running, then open it again and update the auth state (in my case, log out the user) and then the crash happens.

It would be really helpful if you can merge the opened PR to mitigate this.

I have the same issue with firebase_auth 0.16.1 when I use the listener

 Stream<UserModel> get user {
    return _auth.onAuthStateChanged.map(
        (FirebaseUser firebaseUser) => _userFromFirebaseUser(firebaseUser));
  }

When I click on android's back button, and come back on app, it crash

I am seeing the same issue reported in my crashlytics.

Stacktrace is basically identical, except mine has different method name at stackframe 0.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void c.b.b.a.i.a(java.lang.String, java.lang.Object)' on a null object reference
       at io.flutter.plugins.firebaseauth.a$c.a(:45)
       at com.google.firebase.auth.f1.run(:24)
       at android.os.Handler.handleCallback(Handler.java:789)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at b.a.a.a.c.e.o3.dispatchMessage()
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6944)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Device
Brand: samsung
Model: Galaxy S7
Orientation: Portrait
RAM free: 1.14 GB
Disk free: 2.07 GB
Operating System
Version: 8.0.0
Orientation: Portrait
Rooted: No

Pubspec.yaml

version: 1.0.0+1

environment:
    sdk: ">=2.1.0 <3.0.0"

dependencies:
    flutter:
        sdk: flutter
    google_sign_in: ^4.1.1
    cupertino_icons: ^0.1.2
    # http: ^0.12.0+2
    firebase_messaging: ^6.0.16
    firebase_auth: ^0.16.1
    firebase_dynamic_links: ^0.3.0
    firebase_crashlytics: ^0.1.3+3
    overlay_support: ^1.0.4
    stack_trace: "1.9.3"
    ntp: "1.0.7"

dev_dependencies:
    flutter_test:
        sdk: flutter

flutter:
    uses-material-design: true

Hi All - this should now be fixed in the latest version of auth. Closing - please let me know if you continue to have issues.

Was this page helpful?
0 / 5 - 0 ratings