mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 07:59:21 +08:00
Merge pull request #507 from square/eric.null-assertion
Disallow null Type from entering user code.
This commit is contained in:
@@ -92,6 +92,9 @@ public final class Moshi {
|
||||
@CheckReturnValue
|
||||
@SuppressWarnings("unchecked") // Factories are required to return only matching JsonAdapters.
|
||||
public <T> JsonAdapter<T> adapter(Type type, Set<? extends Annotation> annotations) {
|
||||
if (type == null) {
|
||||
throw new NullPointerException("type == null");
|
||||
}
|
||||
if (annotations == null) {
|
||||
throw new NullPointerException("annotations == null");
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -725,6 +726,16 @@ public final class MoshiTest {
|
||||
.isEqualTo("{\"shout\":\"WHAT'S UP\",\"speak\":\"Yo dog\"}");
|
||||
}
|
||||
|
||||
@Test public void adapterLookupDisallowsNullType() {
|
||||
Moshi moshi = new Moshi.Builder().build();
|
||||
try {
|
||||
moshi.adapter(null, Collections.<Annotation>emptySet());
|
||||
fail();
|
||||
} catch (NullPointerException expected) {
|
||||
assertThat(expected).hasMessage("type == null");
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void adapterLookupDisallowsNullAnnotations() {
|
||||
Moshi moshi = new Moshi.Builder().build();
|
||||
try {
|
||||
|
Reference in New Issue
Block a user