Fix null-safety migration bug in VM version of fuse JSON-UTF-8 decoder.

A JSON value can be `null`, so the return type must be `Object?`, not `Object`.

Fixes #46205.

Bug: http://dartbug.com/462051
Change-Id: I9a5522e09765457dcf8cd2639abbe385d97a3186
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202623
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
Lasse Reichstein Holst Nielsen 2021-06-07 11:43:02 +00:00 committed by commit-bot@chromium.org
parent 6d0f90ea54
commit 1154efb073
2 changed files with 6 additions and 2 deletions

View file

@ -63,13 +63,13 @@ class Utf8Decoder {
}
}
class _JsonUtf8Decoder extends Converter<List<int>, Object> {
class _JsonUtf8Decoder extends Converter<List<int>, Object?> {
final Object? Function(Object? key, Object? value)? _reviver;
final bool _allowMalformed;
_JsonUtf8Decoder(this._reviver, this._allowMalformed);
Object convert(List<int> input) {
Object? convert(List<int> input) {
var parser = _JsonUtf8DecoderSink._createParser(_reviver, _allowMalformed);
parser.chunk = input;
parser.chunkEnd = input.length;

View file

@ -53,6 +53,10 @@ void main() {
Expect.throws<FormatException>(
() => parseFuse(" [\xEF\xBB\xBF]".codeUnits.toList()));
// Regression test for dartbug.com/46205
// Bug occurs in sound null safe mode only.
Expect.isNull(parseFuse("null".codeUnits.toList()));
}
Object? parseFuse(List<int> text) {