[tool_crash] _TypeError (Null check operator used on a null value) in ResidentHandlers.debugDumpFocusTree
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
### Description
In Flutter 3.47.3 crash telemetry, `ResidentHandlers.debugDumpFocusTree` threw an unhandled `_TypeError: Null check operator used on a null value` (28 crashes in the first 7 days post-release).
### Stack Trace
```text
ResidentHandlers.debugDumpFocusTree at package:flutter_tools/src/resident_runner.dart:628
TerminalHandler._commonTerminalInputHandler at package:flutter_tools/src/resident_runner.dart:1832
TerminalHandler.processTerminalInput at package:flutter_tools/src/resident_runner.dart:1937
```
### Cause
In `package:flutter_tools/src/resident_runner.dart`:
```dart
Future debugDumpFocusTree() async {
if (!supportsServiceProtocol || !isRunningDebug) {
return false;
}
for (final FlutterDevice? device in flutterDevices) {
final List views = await device!.vmService!.getFlutterViews();
for (final view in views) {
final String data = await device.vmService!.flutterDebugDumpFocusTree(
isolateId: view.uiIsolate!.id!,
);
logger.printStatus(data);
}
}
return true;
}
```
Force unwrapping `view.uiIsolate!.id!` (or `device!.vmService!`) throws a null check operator exception if `view.uiIsolate` is null (e.g. before the isolate finishes initializing or during teardown). Note that `debugDumpLayerTree` has the identical pattern.
### Proposed Fix
Guard `view.uiIsolate?.id` and `device?.vmService` with null checks before invoking service extension methods.
Contributor guide
Assessment
This issue has not been assessed yet.