[flutter_tools] handle NPE in list views method(#59626)

Fixes #59608

The VmService getter can be null, handle that in the listViews method. NNBD when
This commit is contained in:
Jonah Williams
2020-06-17 10:53:54 -07:00
committed by GitHub
parent b8c64d7014
commit 802c4b0f12
2 changed files with 18 additions and 3 deletions

View File

@@ -841,9 +841,14 @@ abstract class ResidentRunner {
/// List the attached flutter views.
Future<List<FlutterView>> listFlutterViews() async {
return (await Future.wait(
flutterDevices.map((FlutterDevice d) => d.vmService.getFlutterViews()))
).expand((List<FlutterView> views) => views).toList();
final List<List<FlutterView>> views = await Future.wait(<Future<List<FlutterView>>>[
for (FlutterDevice device in flutterDevices)
if (device.vmService != null)
device.vmService.getFlutterViews()
]);
return views
.expand((List<FlutterView> viewList) => viewList)
.toList();
}
/// Write the SkSL shaders to a zip file in build directory.

View File

@@ -1044,6 +1044,16 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}));
testUsingContext('listViews handles a null VM service', () => testbed.run(() async {
final FlutterDevice device = FlutterDevice(mockDevice, buildInfo: BuildInfo.debug);
final ResidentRunner residentRunner = HotRunner(
<FlutterDevice>[device],
);
expect(await residentRunner.listFlutterViews(), isEmpty);
}));
testUsingContext('ResidentRunner debugDumpApp calls flutter device', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
await residentRunner.debugDumpApp();