Replace $Gson$Preconditions.checkNotNull
with Objects.requireNonNull
(#2180)
* Replace $Gson$Preconditions.checkNotNull with Objects.requireNonNull * Add back checkNotNull
This commit is contained in:
parent
b0b6834157
commit
7f77ad4ff6
@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
import com.google.gson.internal.$Gson$Preconditions;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A data object that stores attributes of a field.
|
* A data object that stores attributes of a field.
|
||||||
@ -42,8 +42,7 @@ public final class FieldAttributes {
|
|||||||
* @param f the field to pull attributes from
|
* @param f the field to pull attributes from
|
||||||
*/
|
*/
|
||||||
public FieldAttributes(Field f) {
|
public FieldAttributes(Field f) {
|
||||||
$Gson$Preconditions.checkNotNull(f);
|
this.field = Objects.requireNonNull(f);
|
||||||
this.field = f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +54,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
@ -504,9 +505,7 @@ public final class Gson {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> TypeAdapter<T> getAdapter(TypeToken<T> type) {
|
public <T> TypeAdapter<T> getAdapter(TypeToken<T> type) {
|
||||||
if (type == null) {
|
Objects.requireNonNull(type, "type must not be null");
|
||||||
throw new NullPointerException("type must not be null");
|
|
||||||
}
|
|
||||||
TypeAdapter<?> cached = typeTokenCache.get(type);
|
TypeAdapter<?> cached = typeTokenCache.get(type);
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
return (TypeAdapter<T>) cached;
|
return (TypeAdapter<T>) cached;
|
||||||
|
@ -16,26 +16,6 @@
|
|||||||
|
|
||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.google.gson.internal.$Gson$Preconditions;
|
|
||||||
import com.google.gson.internal.Excluder;
|
|
||||||
import com.google.gson.internal.bind.DefaultDateTypeAdapter;
|
|
||||||
import com.google.gson.internal.bind.TreeTypeAdapter;
|
|
||||||
import com.google.gson.internal.bind.TypeAdapters;
|
|
||||||
import com.google.gson.internal.sql.SqlTypesSupport;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
|
||||||
|
|
||||||
import static com.google.gson.Gson.DEFAULT_COMPLEX_MAP_KEYS;
|
import static com.google.gson.Gson.DEFAULT_COMPLEX_MAP_KEYS;
|
||||||
import static com.google.gson.Gson.DEFAULT_DATE_PATTERN;
|
import static com.google.gson.Gson.DEFAULT_DATE_PATTERN;
|
||||||
import static com.google.gson.Gson.DEFAULT_ESCAPE_HTML;
|
import static com.google.gson.Gson.DEFAULT_ESCAPE_HTML;
|
||||||
@ -48,6 +28,26 @@ import static com.google.gson.Gson.DEFAULT_SERIALIZE_NULLS;
|
|||||||
import static com.google.gson.Gson.DEFAULT_SPECIALIZE_FLOAT_VALUES;
|
import static com.google.gson.Gson.DEFAULT_SPECIALIZE_FLOAT_VALUES;
|
||||||
import static com.google.gson.Gson.DEFAULT_USE_JDK_UNSAFE;
|
import static com.google.gson.Gson.DEFAULT_USE_JDK_UNSAFE;
|
||||||
|
|
||||||
|
import com.google.gson.internal.$Gson$Preconditions;
|
||||||
|
import com.google.gson.internal.Excluder;
|
||||||
|
import com.google.gson.internal.bind.DefaultDateTypeAdapter;
|
||||||
|
import com.google.gson.internal.bind.TreeTypeAdapter;
|
||||||
|
import com.google.gson.internal.bind.TypeAdapters;
|
||||||
|
import com.google.gson.internal.sql.SqlTypesSupport;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Use this builder to construct a {@link Gson} instance when you need to set configuration
|
* <p>Use this builder to construct a {@link Gson} instance when you need to set configuration
|
||||||
* options other than the default. For {@link Gson} with default configuration, it is simpler to
|
* options other than the default. For {@link Gson} with default configuration, it is simpler to
|
||||||
@ -166,7 +166,7 @@ public final class GsonBuilder {
|
|||||||
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
|
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
|
||||||
*/
|
*/
|
||||||
public GsonBuilder excludeFieldsWithModifiers(int... modifiers) {
|
public GsonBuilder excludeFieldsWithModifiers(int... modifiers) {
|
||||||
$Gson$Preconditions.checkNotNull(modifiers);
|
Objects.requireNonNull(modifiers);
|
||||||
excluder = excluder.withModifiers(modifiers);
|
excluder = excluder.withModifiers(modifiers);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -310,8 +310,7 @@ public final class GsonBuilder {
|
|||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public GsonBuilder setLongSerializationPolicy(LongSerializationPolicy serializationPolicy) {
|
public GsonBuilder setLongSerializationPolicy(LongSerializationPolicy serializationPolicy) {
|
||||||
$Gson$Preconditions.checkNotNull(serializationPolicy);
|
this.longSerializationPolicy = Objects.requireNonNull(serializationPolicy);
|
||||||
this.longSerializationPolicy = serializationPolicy;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,8 +333,7 @@ public final class GsonBuilder {
|
|||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
|
public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
|
||||||
$Gson$Preconditions.checkNotNull(fieldNamingStrategy);
|
this.fieldNamingPolicy = Objects.requireNonNull(fieldNamingStrategy);
|
||||||
this.fieldNamingPolicy = fieldNamingStrategy;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,8 +345,7 @@ public final class GsonBuilder {
|
|||||||
* @see ToNumberPolicy#DOUBLE The default object-to-number strategy
|
* @see ToNumberPolicy#DOUBLE The default object-to-number strategy
|
||||||
*/
|
*/
|
||||||
public GsonBuilder setObjectToNumberStrategy(ToNumberStrategy objectToNumberStrategy) {
|
public GsonBuilder setObjectToNumberStrategy(ToNumberStrategy objectToNumberStrategy) {
|
||||||
$Gson$Preconditions.checkNotNull(objectToNumberStrategy);
|
this.objectToNumberStrategy = Objects.requireNonNull(objectToNumberStrategy);
|
||||||
this.objectToNumberStrategy = objectToNumberStrategy;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,8 +357,7 @@ public final class GsonBuilder {
|
|||||||
* @see ToNumberPolicy#LAZILY_PARSED_NUMBER The default number-to-number strategy
|
* @see ToNumberPolicy#LAZILY_PARSED_NUMBER The default number-to-number strategy
|
||||||
*/
|
*/
|
||||||
public GsonBuilder setNumberToNumberStrategy(ToNumberStrategy numberToNumberStrategy) {
|
public GsonBuilder setNumberToNumberStrategy(ToNumberStrategy numberToNumberStrategy) {
|
||||||
$Gson$Preconditions.checkNotNull(numberToNumberStrategy);
|
this.numberToNumberStrategy = Objects.requireNonNull(numberToNumberStrategy);
|
||||||
this.numberToNumberStrategy = numberToNumberStrategy;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +374,7 @@ public final class GsonBuilder {
|
|||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
public GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies) {
|
public GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies) {
|
||||||
$Gson$Preconditions.checkNotNull(strategies);
|
Objects.requireNonNull(strategies);
|
||||||
for (ExclusionStrategy strategy : strategies) {
|
for (ExclusionStrategy strategy : strategies) {
|
||||||
excluder = excluder.withExclusionStrategy(strategy, true, true);
|
excluder = excluder.withExclusionStrategy(strategy, true, true);
|
||||||
}
|
}
|
||||||
@ -398,7 +394,7 @@ public final class GsonBuilder {
|
|||||||
* @since 1.7
|
* @since 1.7
|
||||||
*/
|
*/
|
||||||
public GsonBuilder addSerializationExclusionStrategy(ExclusionStrategy strategy) {
|
public GsonBuilder addSerializationExclusionStrategy(ExclusionStrategy strategy) {
|
||||||
$Gson$Preconditions.checkNotNull(strategy);
|
Objects.requireNonNull(strategy);
|
||||||
excluder = excluder.withExclusionStrategy(strategy, true, false);
|
excluder = excluder.withExclusionStrategy(strategy, true, false);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -416,7 +412,7 @@ public final class GsonBuilder {
|
|||||||
* @since 1.7
|
* @since 1.7
|
||||||
*/
|
*/
|
||||||
public GsonBuilder addDeserializationExclusionStrategy(ExclusionStrategy strategy) {
|
public GsonBuilder addDeserializationExclusionStrategy(ExclusionStrategy strategy) {
|
||||||
$Gson$Preconditions.checkNotNull(strategy);
|
Objects.requireNonNull(strategy);
|
||||||
excluder = excluder.withExclusionStrategy(strategy, false, true);
|
excluder = excluder.withExclusionStrategy(strategy, false, true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -547,7 +543,7 @@ public final class GsonBuilder {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
|
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
|
||||||
$Gson$Preconditions.checkNotNull(type);
|
Objects.requireNonNull(type);
|
||||||
$Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|
$Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|
||||||
|| typeAdapter instanceof JsonDeserializer<?>
|
|| typeAdapter instanceof JsonDeserializer<?>
|
||||||
|| typeAdapter instanceof InstanceCreator<?>
|
|| typeAdapter instanceof InstanceCreator<?>
|
||||||
@ -574,7 +570,7 @@ public final class GsonBuilder {
|
|||||||
* @since 2.1
|
* @since 2.1
|
||||||
*/
|
*/
|
||||||
public GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory factory) {
|
public GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory factory) {
|
||||||
$Gson$Preconditions.checkNotNull(factory);
|
Objects.requireNonNull(factory);
|
||||||
factories.add(factory);
|
factories.add(factory);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -595,7 +591,7 @@ public final class GsonBuilder {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
|
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
|
||||||
$Gson$Preconditions.checkNotNull(baseType);
|
Objects.requireNonNull(baseType);
|
||||||
$Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|
$Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|
||||||
|| typeAdapter instanceof JsonDeserializer<?>
|
|| typeAdapter instanceof JsonDeserializer<?>
|
||||||
|| typeAdapter instanceof TypeAdapter<?>);
|
|| typeAdapter instanceof TypeAdapter<?>);
|
||||||
@ -669,7 +665,7 @@ public final class GsonBuilder {
|
|||||||
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
|
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
|
||||||
*/
|
*/
|
||||||
public GsonBuilder addReflectionAccessFilter(ReflectionAccessFilter filter) {
|
public GsonBuilder addReflectionAccessFilter(ReflectionAccessFilter filter) {
|
||||||
$Gson$Preconditions.checkNotNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
reflectionFilters.addFirst(filter);
|
reflectionFilters.addFirst(filter);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
import com.google.gson.internal.$Gson$Preconditions;
|
|
||||||
import com.google.gson.internal.LazilyParsedNumber;
|
import com.google.gson.internal.LazilyParsedNumber;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class representing a JSON primitive value. A primitive value
|
* A class representing a JSON primitive value. A primitive value
|
||||||
@ -40,7 +40,7 @@ public final class JsonPrimitive extends JsonElement {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation") // superclass constructor
|
@SuppressWarnings("deprecation") // superclass constructor
|
||||||
public JsonPrimitive(Boolean bool) {
|
public JsonPrimitive(Boolean bool) {
|
||||||
value = $Gson$Preconditions.checkNotNull(bool);
|
value = Objects.requireNonNull(bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +50,7 @@ public final class JsonPrimitive extends JsonElement {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation") // superclass constructor
|
@SuppressWarnings("deprecation") // superclass constructor
|
||||||
public JsonPrimitive(Number number) {
|
public JsonPrimitive(Number number) {
|
||||||
value = $Gson$Preconditions.checkNotNull(number);
|
value = Objects.requireNonNull(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,7 +60,7 @@ public final class JsonPrimitive extends JsonElement {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation") // superclass constructor
|
@SuppressWarnings("deprecation") // superclass constructor
|
||||||
public JsonPrimitive(String string) {
|
public JsonPrimitive(String string) {
|
||||||
value = $Gson$Preconditions.checkNotNull(string);
|
value = Objects.requireNonNull(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +73,7 @@ public final class JsonPrimitive extends JsonElement {
|
|||||||
public JsonPrimitive(Character c) {
|
public JsonPrimitive(Character c) {
|
||||||
// convert characters to strings since in JSON, characters are represented as a single
|
// convert characters to strings since in JSON, characters are represented as a single
|
||||||
// character string
|
// character string
|
||||||
value = $Gson$Preconditions.checkNotNull(c).toString();
|
value = Objects.requireNonNull(c).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.google.gson.internal;
|
package com.google.gson.internal;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple utility class used to check method Preconditions.
|
* A simple utility class used to check method Preconditions.
|
||||||
*
|
*
|
||||||
@ -34,6 +36,12 @@ public final class $Gson$Preconditions {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* This is an internal Gson method. Use {@link Objects#requireNonNull(Object)} instead.
|
||||||
|
*/
|
||||||
|
// Only deprecated for now because external projects might be using this by accident
|
||||||
|
@Deprecated
|
||||||
public static <T> T checkNotNull(T obj) {
|
public static <T> T checkNotNull(T obj) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.google.gson.internal;
|
package com.google.gson.internal;
|
||||||
|
|
||||||
import static com.google.gson.internal.$Gson$Preconditions.checkArgument;
|
import static com.google.gson.internal.$Gson$Preconditions.checkArgument;
|
||||||
import static com.google.gson.internal.$Gson$Preconditions.checkNotNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
@ -486,7 +486,7 @@ public final class $Gson$Types {
|
|||||||
private final Type[] typeArguments;
|
private final Type[] typeArguments;
|
||||||
|
|
||||||
public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) {
|
public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) {
|
||||||
checkNotNull(rawType);
|
requireNonNull(rawType);
|
||||||
// require an owner type if the raw type needs it
|
// require an owner type if the raw type needs it
|
||||||
if (rawType instanceof Class<?>) {
|
if (rawType instanceof Class<?>) {
|
||||||
Class<?> rawTypeAsClass = (Class<?>) rawType;
|
Class<?> rawTypeAsClass = (Class<?>) rawType;
|
||||||
@ -499,7 +499,7 @@ public final class $Gson$Types {
|
|||||||
this.rawType = canonicalize(rawType);
|
this.rawType = canonicalize(rawType);
|
||||||
this.typeArguments = typeArguments.clone();
|
this.typeArguments = typeArguments.clone();
|
||||||
for (int t = 0, length = this.typeArguments.length; t < length; t++) {
|
for (int t = 0, length = this.typeArguments.length; t < length; t++) {
|
||||||
checkNotNull(this.typeArguments[t]);
|
requireNonNull(this.typeArguments[t]);
|
||||||
checkNotPrimitive(this.typeArguments[t]);
|
checkNotPrimitive(this.typeArguments[t]);
|
||||||
this.typeArguments[t] = canonicalize(this.typeArguments[t]);
|
this.typeArguments[t] = canonicalize(this.typeArguments[t]);
|
||||||
}
|
}
|
||||||
@ -553,7 +553,7 @@ public final class $Gson$Types {
|
|||||||
private final Type componentType;
|
private final Type componentType;
|
||||||
|
|
||||||
public GenericArrayTypeImpl(Type componentType) {
|
public GenericArrayTypeImpl(Type componentType) {
|
||||||
checkNotNull(componentType);
|
requireNonNull(componentType);
|
||||||
this.componentType = canonicalize(componentType);
|
this.componentType = canonicalize(componentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,14 +592,14 @@ public final class $Gson$Types {
|
|||||||
checkArgument(upperBounds.length == 1);
|
checkArgument(upperBounds.length == 1);
|
||||||
|
|
||||||
if (lowerBounds.length == 1) {
|
if (lowerBounds.length == 1) {
|
||||||
checkNotNull(lowerBounds[0]);
|
requireNonNull(lowerBounds[0]);
|
||||||
checkNotPrimitive(lowerBounds[0]);
|
checkNotPrimitive(lowerBounds[0]);
|
||||||
checkArgument(upperBounds[0] == Object.class);
|
checkArgument(upperBounds[0] == Object.class);
|
||||||
this.lowerBound = canonicalize(lowerBounds[0]);
|
this.lowerBound = canonicalize(lowerBounds[0]);
|
||||||
this.upperBound = Object.class;
|
this.upperBound = Object.class;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
checkNotNull(upperBounds[0]);
|
requireNonNull(upperBounds[0]);
|
||||||
checkNotPrimitive(upperBounds[0]);
|
checkNotPrimitive(upperBounds[0]);
|
||||||
this.lowerBound = null;
|
this.lowerBound = null;
|
||||||
this.upperBound = canonicalize(upperBounds[0]);
|
this.upperBound = canonicalize(upperBounds[0]);
|
||||||
|
@ -28,6 +28,7 @@ import com.google.gson.stream.MalformedJsonException;
|
|||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads and writes GSON parse trees over streams.
|
* Reads and writes GSON parse trees over streams.
|
||||||
@ -105,7 +106,7 @@ public final class Streams {
|
|||||||
|
|
||||||
@Override public void write(String str, int off, int len) throws IOException {
|
@Override public void write(String str, int off, int len) throws IOException {
|
||||||
// Appendable.append turns null -> "null", which is not desired here
|
// Appendable.append turns null -> "null", which is not desired here
|
||||||
$Gson$Preconditions.checkNotNull(str);
|
Objects.requireNonNull(str);
|
||||||
appendable.append(str, off, off + len);
|
appendable.append(str, off, off + len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,13 +16,6 @@
|
|||||||
|
|
||||||
package com.google.gson.internal.bind;
|
package com.google.gson.internal.bind;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.lang.reflect.GenericArrayType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.TypeAdapter;
|
import com.google.gson.TypeAdapter;
|
||||||
import com.google.gson.TypeAdapterFactory;
|
import com.google.gson.TypeAdapterFactory;
|
||||||
@ -31,6 +24,11 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonToken;
|
import com.google.gson.stream.JsonToken;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.lang.reflect.GenericArrayType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapt an array of objects.
|
* Adapt an array of objects.
|
||||||
|
@ -16,6 +16,15 @@
|
|||||||
|
|
||||||
package com.google.gson.internal.bind;
|
package com.google.gson.internal.bind;
|
||||||
|
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.TypeAdapterFactory;
|
||||||
|
import com.google.gson.internal.JavaVersion;
|
||||||
|
import com.google.gson.internal.PreJava9DateFormatProvider;
|
||||||
|
import com.google.gson.internal.bind.util.ISO8601Utils;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
@ -25,17 +34,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
import com.google.gson.TypeAdapter;
|
|
||||||
import com.google.gson.TypeAdapterFactory;
|
|
||||||
import com.google.gson.internal.$Gson$Preconditions;
|
|
||||||
import com.google.gson.internal.JavaVersion;
|
|
||||||
import com.google.gson.internal.PreJava9DateFormatProvider;
|
|
||||||
import com.google.gson.internal.bind.util.ISO8601Utils;
|
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
import com.google.gson.stream.JsonToken;
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This type adapter supports subclasses of date by defining a
|
* This type adapter supports subclasses of date by defining a
|
||||||
@ -93,7 +92,7 @@ public final class DefaultDateTypeAdapter<T extends Date> extends TypeAdapter<T>
|
|||||||
private final List<DateFormat> dateFormats = new ArrayList<>();
|
private final List<DateFormat> dateFormats = new ArrayList<>();
|
||||||
|
|
||||||
private DefaultDateTypeAdapter(DateType<T> dateType, String datePattern) {
|
private DefaultDateTypeAdapter(DateType<T> dateType, String datePattern) {
|
||||||
this.dateType = $Gson$Preconditions.checkNotNull(dateType);
|
this.dateType = Objects.requireNonNull(dateType);
|
||||||
dateFormats.add(new SimpleDateFormat(datePattern, Locale.US));
|
dateFormats.add(new SimpleDateFormat(datePattern, Locale.US));
|
||||||
if (!Locale.getDefault().equals(Locale.US)) {
|
if (!Locale.getDefault().equals(Locale.US)) {
|
||||||
dateFormats.add(new SimpleDateFormat(datePattern));
|
dateFormats.add(new SimpleDateFormat(datePattern));
|
||||||
@ -101,7 +100,7 @@ public final class DefaultDateTypeAdapter<T extends Date> extends TypeAdapter<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DefaultDateTypeAdapter(DateType<T> dateType, int style) {
|
private DefaultDateTypeAdapter(DateType<T> dateType, int style) {
|
||||||
this.dateType = $Gson$Preconditions.checkNotNull(dateType);
|
this.dateType = Objects.requireNonNull(dateType);
|
||||||
dateFormats.add(DateFormat.getDateInstance(style, Locale.US));
|
dateFormats.add(DateFormat.getDateInstance(style, Locale.US));
|
||||||
if (!Locale.getDefault().equals(Locale.US)) {
|
if (!Locale.getDefault().equals(Locale.US)) {
|
||||||
dateFormats.add(DateFormat.getDateInstance(style));
|
dateFormats.add(DateFormat.getDateInstance(style));
|
||||||
@ -112,7 +111,7 @@ public final class DefaultDateTypeAdapter<T extends Date> extends TypeAdapter<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DefaultDateTypeAdapter(DateType<T> dateType, int dateStyle, int timeStyle) {
|
private DefaultDateTypeAdapter(DateType<T> dateType, int dateStyle, int timeStyle) {
|
||||||
this.dateType = $Gson$Preconditions.checkNotNull(dateType);
|
this.dateType = Objects.requireNonNull(dateType);
|
||||||
dateFormats.add(DateFormat.getDateTimeInstance(dateStyle, timeStyle, Locale.US));
|
dateFormats.add(DateFormat.getDateTimeInstance(dateStyle, timeStyle, Locale.US));
|
||||||
if (!Locale.getDefault().equals(Locale.US)) {
|
if (!Locale.getDefault().equals(Locale.US)) {
|
||||||
dateFormats.add(DateFormat.getDateTimeInstance(dateStyle, timeStyle));
|
dateFormats.add(DateFormat.getDateTimeInstance(dateStyle, timeStyle));
|
||||||
|
@ -26,6 +26,7 @@ import java.io.IOException;
|
|||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This writer creates a JsonElement.
|
* This writer creates a JsonElement.
|
||||||
@ -130,9 +131,7 @@ public final class JsonTreeWriter extends JsonWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public JsonWriter name(String name) throws IOException {
|
@Override public JsonWriter name(String name) throws IOException {
|
||||||
if (name == null) {
|
Objects.requireNonNull(name, "name == null");
|
||||||
throw new NullPointerException("name == null");
|
|
||||||
}
|
|
||||||
if (stack.isEmpty() || pendingName != null) {
|
if (stack.isEmpty() || pendingName != null) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.google.gson.reflect;
|
package com.google.gson.reflect;
|
||||||
|
|
||||||
import com.google.gson.internal.$Gson$Preconditions;
|
|
||||||
import com.google.gson.internal.$Gson$Types;
|
import com.google.gson.internal.$Gson$Types;
|
||||||
import java.lang.reflect.GenericArrayType;
|
import java.lang.reflect.GenericArrayType;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
@ -24,6 +23,7 @@ import java.lang.reflect.Type;
|
|||||||
import java.lang.reflect.TypeVariable;
|
import java.lang.reflect.TypeVariable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a generic type {@code T}. Java doesn't yet provide a way to
|
* Represents a generic type {@code T}. Java doesn't yet provide a way to
|
||||||
@ -72,7 +72,7 @@ public class TypeToken<T> {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private TypeToken(Type type) {
|
private TypeToken(Type type) {
|
||||||
this.type = $Gson$Types.canonicalize($Gson$Preconditions.checkNotNull(type));
|
this.type = $Gson$Types.canonicalize(Objects.requireNonNull(type));
|
||||||
this.rawType = (Class<? super T>) $Gson$Types.getRawType(this.type);
|
this.rawType = (Class<? super T>) $Gson$Types.getRawType(this.type);
|
||||||
this.hashCode = this.type.hashCode();
|
this.hashCode = this.type.hashCode();
|
||||||
}
|
}
|
||||||
@ -325,8 +325,8 @@ public class TypeToken<T> {
|
|||||||
* the raw type
|
* the raw type
|
||||||
*/
|
*/
|
||||||
public static TypeToken<?> getParameterized(Type rawType, Type... typeArguments) {
|
public static TypeToken<?> getParameterized(Type rawType, Type... typeArguments) {
|
||||||
$Gson$Preconditions.checkNotNull(rawType);
|
Objects.requireNonNull(rawType);
|
||||||
$Gson$Preconditions.checkNotNull(typeArguments);
|
Objects.requireNonNull(typeArguments);
|
||||||
|
|
||||||
// Perform basic validation here because this is the only public API where users
|
// Perform basic validation here because this is the only public API where users
|
||||||
// can create malformed parameterized types
|
// can create malformed parameterized types
|
||||||
|
@ -23,6 +23,7 @@ import java.io.EOFException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a JSON (<a href="http://www.ietf.org/rfc/rfc7159.txt">RFC 7159</a>)
|
* Reads a JSON (<a href="http://www.ietf.org/rfc/rfc7159.txt">RFC 7159</a>)
|
||||||
@ -287,10 +288,7 @@ public class JsonReader implements Closeable {
|
|||||||
* Creates a new instance that reads a JSON-encoded stream from {@code in}.
|
* Creates a new instance that reads a JSON-encoded stream from {@code in}.
|
||||||
*/
|
*/
|
||||||
public JsonReader(Reader in) {
|
public JsonReader(Reader in) {
|
||||||
if (in == null) {
|
this.in = Objects.requireNonNull(in, "in == null");
|
||||||
throw new NullPointerException("in == null");
|
|
||||||
}
|
|
||||||
this.in = in;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,17 +16,6 @@
|
|||||||
|
|
||||||
package com.google.gson.stream;
|
package com.google.gson.stream;
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.Flushable;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static com.google.gson.stream.JsonScope.DANGLING_NAME;
|
import static com.google.gson.stream.JsonScope.DANGLING_NAME;
|
||||||
import static com.google.gson.stream.JsonScope.EMPTY_ARRAY;
|
import static com.google.gson.stream.JsonScope.EMPTY_ARRAY;
|
||||||
import static com.google.gson.stream.JsonScope.EMPTY_DOCUMENT;
|
import static com.google.gson.stream.JsonScope.EMPTY_DOCUMENT;
|
||||||
@ -35,6 +24,18 @@ import static com.google.gson.stream.JsonScope.NONEMPTY_ARRAY;
|
|||||||
import static com.google.gson.stream.JsonScope.NONEMPTY_DOCUMENT;
|
import static com.google.gson.stream.JsonScope.NONEMPTY_DOCUMENT;
|
||||||
import static com.google.gson.stream.JsonScope.NONEMPTY_OBJECT;
|
import static com.google.gson.stream.JsonScope.NONEMPTY_OBJECT;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.Flushable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a JSON (<a href="http://www.ietf.org/rfc/rfc7159.txt">RFC 7159</a>)
|
* Writes a JSON (<a href="http://www.ietf.org/rfc/rfc7159.txt">RFC 7159</a>)
|
||||||
* encoded value to a stream, one token at a time. The stream includes both
|
* encoded value to a stream, one token at a time. The stream includes both
|
||||||
@ -203,10 +204,7 @@ public class JsonWriter implements Closeable, Flushable {
|
|||||||
* {@link java.io.BufferedWriter BufferedWriter} if necessary.
|
* {@link java.io.BufferedWriter BufferedWriter} if necessary.
|
||||||
*/
|
*/
|
||||||
public JsonWriter(Writer out) {
|
public JsonWriter(Writer out) {
|
||||||
if (out == null) {
|
this.out = Objects.requireNonNull(out, "out == null");
|
||||||
throw new NullPointerException("out == null");
|
|
||||||
}
|
|
||||||
this.out = out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,9 +385,7 @@ public class JsonWriter implements Closeable, Flushable {
|
|||||||
* @return this writer.
|
* @return this writer.
|
||||||
*/
|
*/
|
||||||
public JsonWriter name(String name) throws IOException {
|
public JsonWriter name(String name) throws IOException {
|
||||||
if (name == null) {
|
Objects.requireNonNull(name, "name == null");
|
||||||
throw new NullPointerException("name == null");
|
|
||||||
}
|
|
||||||
if (deferredName != null) {
|
if (deferredName != null) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.google.gson.protobuf;
|
package com.google.gson.protobuf;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
@ -104,7 +104,7 @@ public class ProtoTypeAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Builder setEnumSerialization(EnumSerialization enumSerialization) {
|
public Builder setEnumSerialization(EnumSerialization enumSerialization) {
|
||||||
this.enumSerialization = checkNotNull(enumSerialization);
|
this.enumSerialization = requireNonNull(enumSerialization);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ public class ProtoTypeAdapter
|
|||||||
*/
|
*/
|
||||||
public Builder addSerializedNameExtension(
|
public Builder addSerializedNameExtension(
|
||||||
Extension<FieldOptions, String> serializedNameExtension) {
|
Extension<FieldOptions, String> serializedNameExtension) {
|
||||||
serializedNameExtensions.add(checkNotNull(serializedNameExtension));
|
serializedNameExtensions.add(requireNonNull(serializedNameExtension));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ public class ProtoTypeAdapter
|
|||||||
*/
|
*/
|
||||||
public Builder addSerializedEnumValueExtension(
|
public Builder addSerializedEnumValueExtension(
|
||||||
Extension<EnumValueOptions, String> serializedEnumValueExtension) {
|
Extension<EnumValueOptions, String> serializedEnumValueExtension) {
|
||||||
serializedEnumValueExtensions.add(checkNotNull(serializedEnumValueExtension));
|
serializedEnumValueExtensions.add(requireNonNull(serializedEnumValueExtension));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user