Skip to content

Commit 3b6afe9

Browse files
authored
json_annotation: Fix a potential error with checked: true... (#819)
...when `ArgumentError.message` is `null`
1 parent 999c651 commit 3b6afe9

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

json_annotation/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 4.0.1-dev
2+
3+
- Fix a potential error with `checked: true` when `ArgumentError.message` is
4+
`null`.
5+
16
## 4.0.0
27

38
- Support null safety.

json_annotation/lib/src/checked_helpers.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class CheckedFromJsonException implements Exception {
104104
innerStack = null;
105105

106106
CheckedFromJsonException._(
107-
this.innerError,
107+
Object this.innerError,
108108
this.innerStack,
109109
this.map,
110110
this.key, {
@@ -113,9 +113,12 @@ class CheckedFromJsonException implements Exception {
113113
badKey = innerError is BadKeyException,
114114
message = _getMessage(innerError);
115115

116-
static String? _getMessage(Object? error) {
116+
static String _getMessage(Object error) {
117117
if (error is ArgumentError) {
118-
return error.message?.toString();
118+
final message = error.message;
119+
if (message != null) {
120+
return message.toString();
121+
}
119122
}
120123
if (error is BadKeyException) {
121124
return error.message;

json_annotation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_annotation
2-
version: 4.0.0
2+
version: 4.0.1-dev
33
description: >-
44
Classes and helper functions that support JSON code generation via the
55
`json_serializable` package.

0 commit comments

Comments
 (0)