Skip to content

ui: Incorrect null-check operator in _LoadingPlaceholderPageState.build #1219

@chrisbobbe

Description

@chrisbobbe

To reproduce:

  1. Use a debug build so you can see errors printed to the console
  2. Log into an account
  3. Log out of the account ("Choose account" > three-dots menu > "Log out")
  4. See the following in the console:
======== Exception caught by widgets library =======================================================
The following _TypeError was thrown building _LoadingPlaceholderPage(dirty, dependencies: [_GlobalStoreInheritedWidget, _LocalizationsScope-[GlobalKey#c7674]], state: _LoadingPlaceholderPageState#4549b):
Null check operator used on a null value

The relevant error-causing widget was: 
  _LoadingPlaceholderPage _LoadingPlaceholderPage:file:///Users/chrisbobbe/dev/zulip-flutter/lib/widgets/home.dart:36:31
When the exception was thrown, this was the stack: 
#0      _LoadingPlaceholderPageState.build (package:zulip/widgets/home.dart:184:36)
#1      StatefulElement.build (package:flutter/src/widgets/framework.dart:5841:27)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5733:15)
#3      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5892:11)
#4      Element.rebuild (package:flutter/src/widgets/framework.dart:5445:7)
#5      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5715:5)
#6      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5883:11)
#7      ComponentElement.mount (package:flutter/src/widgets/framework.dart:5709:5)

This is a latent bug introduced in a97ac42 (fyi @PIG208). This widget shouldn't assume that an account for its accountId param exists; in particular, it won't exist in the short period after the account is removed from the database (for logout) and before routeToRemoveOnLogout is processed in a post-frame callback.

I see two plausible fixes:

  • Remove the accountId param and pass…hmm, I guess a realmUrl param, for the "try another account" message. Or:
  • Keep the accountId param but give it dartdoc with a reminder that the corresponding account might not exist, saying why.

In either case we should add a test that would fail before the fix but passes after it.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions