Unverified Commit 53dce17b authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tools] Fallback discovery: Don't crash when an Isolate has no root library (#52354)

parent d19c4434
......@@ -167,7 +167,7 @@ class FallbackDiscovery {
throw Exception('Expected Isolate but found Sentinel: $isolateResponse');
}
final LibraryRef library = (isolateResponse as Isolate).rootLib;
if (library.uri.startsWith('package:$packageName')) {
if (library != null && library.uri.startsWith('package:$packageName')) {
UsageEvent(
_kEventName,
'success',
......
......@@ -67,6 +67,31 @@ void main() {
), Uri.parse('http://localhost:1'));
});
testUsingContext('Selects assumed port when another isolate has no root library', () async {
when(mockVmService.getVM()).thenAnswer((Invocation invocation) async {
return VM()..isolates = <IsolateRef>[
IsolateRef()..id = '1',
IsolateRef()..id = '2',
];
});
when(mockVmService.getIsolate('1')).thenAnswer((Invocation invocation) async {
return Isolate()
..rootLib = null;
});
when(mockVmService.getIsolate('2')).thenAnswer((Invocation invocation) async {
return Isolate()
..rootLib = (LibraryRef()..uri = 'package:hello/main.dart');
});
expect(await fallbackDiscovery.discover(
assumedDevicePort: 23,
deivce: null,
hostVmservicePort: 1,
packageId: null,
usesIpv6: false,
packageName: 'hello',
), Uri.parse('http://localhost:1'));
});
testUsingContext('Selects mdns discovery if VM service connecton fails due to Sentinel', () async {
when(mockVmService.getVM()).thenAnswer((Invocation invocation) async {
return VM()..isolates = <IsolateRef>[
......
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