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

Null check operator used on a null value #67

Open
d9media opened this issue Jan 6, 2022 · 2 comments
Open

Null check operator used on a null value #67

d9media opened this issue Jan 6, 2022 · 2 comments

Comments

@d9media
Copy link

d9media commented Jan 6, 2022

Hi guys,

I recently investigated an issue where our app would get stuck at splashscreen for some users. I'm now convinced I can reproduce the issue.

When you enable "use network-provided time zone" in Android (settings > system > date&time) , initialization of TimeMachine fails with the following stacktrace:

I/flutter (26553): ----------------FIREBASE CRASHLYTICS----------------
I/flutter (26553): Null check operator used on a null value
I/flutter (26553):
I/flutter (26553): #0      TimeMachine.initialize
package:time_machine/…/platforms/vm.dart:95
I/flutter (26553): <asynchronous suspension>
I/flutter (26553): #1      main.<anonymous closure>
package:***/main.dart:115
I/flutter (26553): <asynchronous suspension>
I/flutter (26553): #2      main
package:***/main.dart:110
I/flutter (26553): <asynchronous suspension>

pointing to vm.dart:93 ff.:

   var local = timeZoneOverride != null ? await tzdb.getZoneOrNull(timeZoneOverride) : await _figureOutTimeZone(tzdb);
    // todo: cache local more directly? (this is indirect caching)
    TzdbIndex.localId = local!.id;   // <-- baaang

When you set a location instead, everything works. I can't say whether this is an issue for iOS too but we did have user reports with a similar crash pattern.

It looks local can be null when network-provided time fails or timezone is set to GMT. In that case, we can't use null operator.

I don't really know TimeMachine well enough yet to suggest a solution but I still wanted to bring this your attention.

@rich-j
Copy link
Contributor

rich-j commented Dec 28, 2022

We've hit this with Android Play store testing where some of the test devices have uncommon/undefined time zone names. I don't know if TimeMachine could provide a reasonable fallback default. We have implemented our own fallback to UTC (which is always defined) when the initialize throws an exception:

FlutterTimezone.getLocalTimezone()
  .then((timeZone) => TimeMachine.initialize({"rootBundle": kIsWeb ? null : rootBundle, "timeZone": timeZone}))
  .catchError((_) => TimeMachine.initialize({"rootBundle": kIsWeb ? null : rootBundle, "timeZone": "UTC"}));

@tigloo
Copy link

tigloo commented Jan 7, 2025

I fixed the issue in the fork here: https://pub.dev/packages/time_machine2

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

No branches or pull requests

3 participants