Skip to content
Merged
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 @@ -378,8 +378,11 @@ public AtomicLongArray read(JsonReader in) throws IOException {
List<Long> list = new ArrayList<>();
in.beginArray();
while (in.hasNext()) {
long value = longAdapter.read(in).longValue();
list.add(value);
Number value = longAdapter.read(in);
if (value == null) {
throw new JsonSyntaxException("null is not a valid AtomicLongArray element");
}
list.add(value.longValue());
}
in.endArray();
int length = list.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.google.gson.functional;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.google.gson.LongSerializationPolicy;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -113,4 +115,12 @@ public void testAtomicLongArrayWithStringSerializationPolicy() {
private static class AtomicLongHolder {
AtomicLong value;
}

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