Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ public AtomicIntegerArray read(JsonReader in) throws IOException {
in.beginArray();
while (in.hasNext()) {
try {
if (in.peek() == JsonToken.NULL) {
throw new JsonSyntaxException(
"null is not a valid AtomicIntegerArray element; at path " + in.getPath());
}
int integer = in.nextInt();
list.add(integer);
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ public void testAtomicLongArrayWithNullElement() {
.hasMessageThat()
.isEqualTo("null is not a valid AtomicLongArray element; at path $[1]");
}

@Test
public void testAtomicIntegerArrayWithNullElement() {
JsonSyntaxException e =
assertThrows(
JsonSyntaxException.class, () -> gson.fromJson("[1,null,3]", AtomicIntegerArray.class));
assertThat(e)
.hasMessageThat()
.isEqualTo("null is not a valid AtomicIntegerArray element; at path $[1]");
}
}
Loading