diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index ce85f6123..eedb1906b 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,3 +1,7 @@ +## 21.0.0+1 + +- Fix a null cast error when debugging a `Class` from VS Code. - [#2303](https://github.com/dart-lang/webdev/pull/2303) + ## 21.0.0 - Update Dart SDK constraint to `>=3.2.0-36.0.dev <4.0.0`. - [#2207](https://github.com/dart-lang/webdev/pull/2207) diff --git a/dwds/lib/src/debugging/classes.dart b/dwds/lib/src/debugging/classes.dart index 1cd7da567..2ca2f9723 100644 --- a/dwds/lib/src/debugging/classes.dart +++ b/dwds/lib/src/debugging/classes.dart @@ -96,10 +96,9 @@ class ClassHelper extends Domain { throw ChromeDebugException(e.json, evalContents: expression); } - final classDescriptor = result.value as Map; + final classDescriptor = _mapify(result.value); final methodRefs = []; - final methodDescriptors = - classDescriptor['methods'] as Map; + final methodDescriptors = _mapify(classDescriptor['methods']); methodDescriptors.forEach((name, descriptor) { final methodId = 'methods|$classId|$name'; methodRefs.add( @@ -118,7 +117,7 @@ class ClassHelper extends Domain { }); final fieldRefs = []; - final fieldDescriptors = classDescriptor['fields'] as Map; + final fieldDescriptors = _mapify(classDescriptor['fields']); fieldDescriptors.forEach((name, descriptor) { final classMetaData = ClassMetaData( runtimeKind: RuntimeObjectKind.type, @@ -168,4 +167,7 @@ class ClassHelper extends Domain { superClass: superClassRef, ); } + + Map _mapify(dynamic map) => + (map as Map?) ?? {}; }