Skip to content

Commit defa4bc

Browse files
authored
Change cast in json parsing (#137708)
`jsonDecode` decodes lists as `List<Object?>`, so the cast to `List<Object>` fails at runtime in sound null safety mode.
1 parent 3649deb commit defa4bc

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/flutter_tools/lib/src/proxied_devices/file_transfer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class BlockHashes {
5151
blockSize: obj['blockSize']! as int,
5252
totalSize: obj['totalSize']! as int,
5353
adler32: Uint32List.view(base64.decode(obj['adler32']! as String).buffer),
54-
md5: (obj['md5']! as List<Object>).cast<String>(),
54+
md5: (obj['md5']! as List<Object?>).cast<String>(),
5555
fileMd5: obj['fileMd5']! as String,
5656
);
5757
}

packages/flutter_tools/test/general.shard/proxied_devices/file_transfer_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,26 @@ void main() {
187187
expect(file.readAsStringSync(), content2);
188188
});
189189
});
190+
191+
group('BlockHashes', () {
192+
test('json conversion works normally', () {
193+
const String json = '''
194+
{
195+
"blockSize":4,
196+
"totalSize":18,
197+
"adler32":"7ACcAu0AoALuAKQC7wCoApQA+gA=",
198+
"md5": [
199+
"zB0S8R/fGt05GcI5v8AjIQ==",
200+
"uZCZ4i/LUGFYAD+K1ZD0Wg==",
201+
"6kbZGS8T1NJl/naWODQcNw==",
202+
"kKh/aA2XAhR/r0HdZa3Bxg==",
203+
"34eF7Bs/OhfoJ5+sAw0zyw=="
204+
],
205+
"fileMd5":"VT/gkSEdctzUEUJCxclxuQ=="
206+
}
207+
''';
208+
final Map<String, Object?> decodedJson = jsonDecode(json) as Map<String, Object?>;
209+
expect(BlockHashes.fromJson(decodedJson).toJson(), decodedJson);
210+
});
211+
});
190212
}

0 commit comments

Comments
 (0)