Unverified Commit 802c4b0f authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[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
parent b8c64d70
...@@ -841,9 +841,14 @@ abstract class ResidentRunner { ...@@ -841,9 +841,14 @@ abstract class ResidentRunner {
/// List the attached flutter views. /// List the attached flutter views.
Future<List<FlutterView>> listFlutterViews() async { Future<List<FlutterView>> listFlutterViews() async {
return (await Future.wait( final List<List<FlutterView>> views = await Future.wait(<Future<List<FlutterView>>>[
flutterDevices.map((FlutterDevice d) => d.vmService.getFlutterViews())) for (FlutterDevice device in flutterDevices)
).expand((List<FlutterView> views) => views).toList(); 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. /// Write the SkSL shaders to a zip file in build directory.
......
...@@ -1044,6 +1044,16 @@ void main() { ...@@ -1044,6 +1044,16 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false); 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 { testUsingContext('ResidentRunner debugDumpApp calls flutter device', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
await residentRunner.debugDumpApp(); await residentRunner.debugDumpApp();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment