Unverified Commit df669ab1 authored by Dan Field's avatar Dan Field Committed by GitHub

Avoid NPE for flutter attach mDNS (#31926)

parent 6a69f8c9
......@@ -216,7 +216,9 @@ class AttachCommand extends FlutterCommand {
}
} else if ((device is IOSDevice) || (device is IOSSimulator)) {
final MDnsObservatoryDiscoveryResult result = await MDnsObservatoryDiscovery().query(applicationId: appId);
observatoryUri = await _buildObservatoryUri(device, hostname, result.port, result.authCode);
if (result != null) {
observatoryUri = await _buildObservatoryUri(device, hostname, result.port, result.authCode);
}
}
// If MDNS discovery fails or we're not on iOS, fallback to ProtocolDiscovery.
if (observatoryUri == null) {
......
......@@ -537,6 +537,17 @@ void main() {
final int port = (await portDiscovery.query(applicationId: 'bar'))?.port;
expect(port, 1234);
});
testUsingContext('Query returns null', () async {
final MDnsClient client = getMockClient(
<PtrResourceRecord>[],
<String, List<SrvResourceRecord>>{},
);
final MDnsObservatoryDiscovery portDiscovery = MDnsObservatoryDiscovery(mdnsClient: client);
final int port = (await portDiscovery.query(applicationId: 'bar'))?.port;
expect(port, isNull);
});
});
}
......
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