Skip to content

Commit 7a8c65d

Browse files
authored
handle null functions key in cpu samples (#8940)
Fixes one of the errors shown in #8866.
1 parent f287785 commit 7a8c65d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ class _CpuProfileTimelineTree {
12231223
if (isCodeTree) {
12241224
return _code.function!;
12251225
}
1226-
final function = samples.functions![index].function;
1226+
final function = samples.functions?[index].function;
12271227
if (function is vm_service.FuncRef ||
12281228
function is vm_service.NativeFunction) {
12291229
return function;
@@ -1263,7 +1263,7 @@ class _CpuProfileTimelineTree {
12631263
// critical since this is only displayed when VM developer mode is
12641264
// enabled.
12651265
(_function as vm_service.FuncRef?)?.location?.script?.uri
1266-
: samples.functions![index].resolvedUrl;
1266+
: samples.functions?[index].resolvedUrl;
12671267

12681268
int? get sourceLine {
12691269
final function = _function;

packages/devtools_app/test/screens/cpu_profiler/cpu_profile_model_test.dart

+12
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ void main() {
122122
);
123123
});
124124

125+
test('converts samples with no functions regression test', () {
126+
expect(
127+
// False positive for this lint, it is used by the matcher.
128+
// ignore: discarded_futures
129+
CpuProfileData.generateFromCpuSamples(
130+
isolateId: goldenSamplesIsolate,
131+
cpuSamples: CpuSamples.parse(goldenCpuSamplesJson)!..functions = null,
132+
),
133+
completes,
134+
);
135+
});
136+
125137
test('to json defaults packageUri to resolvedUrl', () {
126138
const id = '140357727781376-12';
127139

0 commit comments

Comments
 (0)