Skip to content

Commit

Permalink
Address some code scanning findings
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcono1234 committed Feb 16, 2022
1 parent a29ad1e commit 7337057
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* A type adapter factory that implements {@code @Intercept}.
*/
public final class InterceptorFactory implements TypeAdapterFactory {
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
@Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Intercept intercept = type.getRawType().getAnnotation(Intercept.class);
if (intercept == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public User(String name, String password) {
}

public static final class UserValidator implements JsonPostDeserializer<User> {
public void postDeserialize(User user) {
@Override public void postDeserialize(User user) {
if (user.name == null || user.password == null) {
throw new JsonSyntaxException("name and password are required fields.");
}
Expand All @@ -161,7 +161,7 @@ private static final class Address {
}

public static final class AddressValidator implements JsonPostDeserializer<Address> {
public void postDeserialize(Address address) {
@Override public void postDeserialize(Address address) {
if (address.city == null || address.state == null || address.zip == null) {
throw new JsonSyntaxException("Address city, state and zip are required fields.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public Sandwich(String bread, String cheese) {
}
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
Expand All @@ -95,6 +96,7 @@ public MultipleSandwiches(List<Sandwich> sandwiches) {
this.sandwiches = sandwiches;
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
Expand Down
6 changes: 3 additions & 3 deletions gson/src/main/java/com/google/gson/JsonArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public boolean isEmpty() {
*
* @return an iterator to navigate the elements of the array.
*/
@Override
public Iterator<JsonElement> iterator() {
return elements.iterator();
}
Expand Down Expand Up @@ -341,13 +342,12 @@ public byte getAsByte() {
throw new IllegalStateException();
}

@Deprecated
@Override
public char getAsCharacter() {
if (elements.size() == 1) {
JsonElement element = elements.get(0);
@SuppressWarnings("deprecation")
char result = element.getAsCharacter();
return result;
return element.getAsCharacter();
}
throw new IllegalStateException();
}
Expand Down
5 changes: 4 additions & 1 deletion gson/src/main/java/com/google/gson/JsonStreamParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class JsonStreamParser implements Iterator<JsonElement> {
* @since 1.4
*/
public JsonStreamParser(String json) {
this(new StringReader(json));
this(new StringReader(json));
}

/**
Expand All @@ -81,6 +81,7 @@ public JsonStreamParser(Reader reader) {
* @throws NoSuchElementException if no {@code JsonElement} is available.
* @since 1.4
*/
@Override
public JsonElement next() throws JsonParseException {
if (!hasNext()) {
throw new NoSuchElementException();
Expand All @@ -103,6 +104,7 @@ public JsonElement next() throws JsonParseException {
* @throws JsonSyntaxException if the incoming stream is malformed JSON.
* @since 1.4
*/
@Override
public boolean hasNext() {
synchronized (lock) {
try {
Expand All @@ -120,6 +122,7 @@ public boolean hasNext() {
* implemented.
* @since 1.4
*/
@Override
public void remove() {
throw new UnsupportedOperationException();
}
Expand Down
12 changes: 6 additions & 6 deletions gson/src/main/java/com/google/gson/internal/$Gson$Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,15 @@ public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments
}
}

public Type[] getActualTypeArguments() {
@Override public Type[] getActualTypeArguments() {
return typeArguments.clone();
}

public Type getRawType() {
@Override public Type getRawType() {
return rawType;
}

public Type getOwnerType() {
@Override public Type getOwnerType() {
return ownerType;
}

Expand Down Expand Up @@ -552,7 +552,7 @@ public GenericArrayTypeImpl(Type componentType) {
this.componentType = canonicalize(componentType);
}

public Type getGenericComponentType() {
@Override public Type getGenericComponentType() {
return componentType;
}

Expand Down Expand Up @@ -601,11 +601,11 @@ public WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
}
}

public Type[] getUpperBounds() {
@Override public Type[] getUpperBounds() {
return new Type[] { upperBound };
}

public Type[] getLowerBounds() {
@Override public Type[] getLowerBounds() {
return lowerBound != null ? new Type[] { lowerBound } : EMPTY_TYPE_ARRAY;
}

Expand Down
2 changes: 1 addition & 1 deletion gson/src/main/java/com/google/gson/internal/Excluder.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Excluder withExclusionStrategy(ExclusionStrategy exclusionStrategy,
return result;
}

public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
@Override public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
Class<?> rawType = type.getRawType();
boolean excludeClass = excludeClassChecks(rawType);

Expand Down
16 changes: 8 additions & 8 deletions gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public final class LinkedTreeMap<K, V> extends AbstractMap<K, V> implements Serializable {
@SuppressWarnings({ "unchecked", "rawtypes" }) // to avoid Comparable<Comparable<Comparable<...>>>
private static final Comparator<Comparable> NATURAL_ORDER = new Comparator<Comparable>() {
public int compare(Comparable a, Comparable b) {
@Override public int compare(Comparable a, Comparable b) {
return a.compareTo(b);
}
};
Expand Down Expand Up @@ -466,15 +466,15 @@ static final class Node<K, V> implements Entry<K, V> {
next.prev = this;
}

public K getKey() {
@Override public K getKey() {
return key;
}

public V getValue() {
@Override public V getValue() {
return value;
}

public V setValue(V value) {
@Override public V setValue(V value) {
V oldValue = this.value;
this.value = value;
return oldValue;
Expand Down Expand Up @@ -534,7 +534,7 @@ private abstract class LinkedTreeMapIterator<T> implements Iterator<T> {
LinkedTreeMapIterator() {
}

public final boolean hasNext() {
@Override public final boolean hasNext() {
return next != header;
}

Expand All @@ -550,7 +550,7 @@ final Node<K, V> nextNode() {
return lastReturned = e;
}

public final void remove() {
@Override public final void remove() {
if (lastReturned == null) {
throw new IllegalStateException();
}
Expand All @@ -567,7 +567,7 @@ class EntrySet extends AbstractSet<Entry<K, V>> {

@Override public Iterator<Entry<K, V>> iterator() {
return new LinkedTreeMapIterator<Entry<K, V>>() {
public Entry<K, V> next() {
@Override public Entry<K, V> next() {
return nextNode();
}
};
Expand Down Expand Up @@ -602,7 +602,7 @@ final class KeySet extends AbstractSet<K> {

@Override public Iterator<K> iterator() {
return new LinkedTreeMapIterator<K>() {
public K next() {
@Override public K next() {
return nextNode().key;
}
};
Expand Down
6 changes: 3 additions & 3 deletions gson/src/main/java/com/google/gson/internal/Streams.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ private static final class AppendableWriter extends Writer {
*/
static class CurrentWrite implements CharSequence {
char[] chars;
public int length() {
@Override public int length() {
return chars.length;
}
public char charAt(int i) {
@Override public char charAt(int i) {
return chars[i];
}
public CharSequence subSequence(int start, int end) {
@Override public CharSequence subSequence(int start, int end) {
return new String(chars, start, end - start);
}
}
Expand Down
2 changes: 1 addition & 1 deletion gson/src/main/java/com/google/gson/stream/JsonReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ public int nextInt() throws IOException {
/**
* Closes this JSON reader and the underlying {@link java.io.Reader}.
*/
public void close() throws IOException {
@Override public void close() throws IOException {
peeked = PEEKED_NONE;
stack[0] = JsonScope.CLOSED;
stackSize = 1;
Expand Down
4 changes: 2 additions & 2 deletions gson/src/main/java/com/google/gson/stream/JsonWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public JsonWriter value(Number value) throws IOException {
* Ensures all buffered data is written to the underlying {@link Writer}
* and flushes that writer.
*/
public void flush() throws IOException {
@Override public void flush() throws IOException {
if (stackSize == 0) {
throw new IllegalStateException("JsonWriter is closed.");
}
Expand All @@ -583,7 +583,7 @@ public void flush() throws IOException {
*
* @throws IOException if the JSON document is incomplete.
*/
public void close() throws IOException {
@Override public void close() throws IOException {
out.close();

int size = stackSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void testDeserializerForAbstractClass() {
private void assertSerialized(String expected, Class<?> instanceType, boolean registerAbstractDeserializer,
boolean registerAbstractHierarchyDeserializer, Object instance) {
JsonDeserializer<Abstract> deserializer = new JsonDeserializer<Abstract>() {
public Abstract deserialize(JsonElement json, Type typeOfT,
@Override public Abstract deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testSelfReferenceCustomHandlerSerialization() throws Exception {
ClassWithSelfReference obj = new ClassWithSelfReference();
obj.child = obj;
Gson gson = new GsonBuilder().registerTypeAdapter(ClassWithSelfReference.class, new JsonSerializer<ClassWithSelfReference>() {
public JsonElement serialize(ClassWithSelfReference src, Type typeOfSrc,
@Override public JsonElement serialize(ClassWithSelfReference src, Type typeOfSrc,
JsonSerializationContext context) {
JsonObject obj = new JsonObject();
obj.addProperty("property", "value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void testFieldIsArrayList() {
public void testUserCollectionTypeAdapter() {
Type listOfString = new TypeToken<List<String>>() {}.getType();
Object stringListSerializer = new JsonSerializer<List<String>>() {
public JsonElement serialize(List<String> src, Type typeOfSrc,
@Override public JsonElement serialize(List<String> src, Type typeOfSrc,
JsonSerializationContext context) {
return new JsonPrimitive(src.get(0) + ";" + src.get(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testMultiThreadSerialization() throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int taskCount = 0; taskCount < 10; taskCount++) {
executor.execute(new Runnable() {
public void run() {
@Override public void run() {
MyObject myObj = new MyObject();
try {
startLatch.await();
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testMultiThreadDeserialization() throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int taskCount = 0; taskCount < 10; taskCount++) {
executor.execute(new Runnable() {
public void run() {
@Override public void run() {
try {
startLatch.await();
for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testBaseClassSerializerInvokedForBaseClassFieldsHoldingSubClassInsta
public void testSerializerReturnsNull() {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Base.class, new JsonSerializer<Base>() {
public JsonElement serialize(Base src, Type typeOfSrc, JsonSerializationContext context) {
@Override public JsonElement serialize(Base src, Type typeOfSrc, JsonSerializationContext context) {
return null;
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public void testDateSerializationWithPatternNotOverridenByTypeAdapter() throws E
Gson gson = new GsonBuilder()
.setDateFormat(pattern)
.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
public Date deserialize(JsonElement json, Type typeOfT,
@Override public Date deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context)
throws JsonParseException {
return new Date(1315806903103L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class GsonVersionDiagnosticsTest extends TestCase {
private Gson gson;

@Before
@Override
public void setUp() {
gson = new GsonBuilder().registerTypeAdapter(TestType.class, new TypeAdapter<TestType>() {
@Override public void write(JsonWriter out, TestType value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testRegisteredAdapterOverridesJsonAdapter() {
*/
public void testRegisteredSerializerOverridesJsonAdapter() {
JsonSerializer<A> serializer = new JsonSerializer<A>() {
public JsonElement serialize(A src, Type typeOfSrc,
@Override public JsonElement serialize(A src, Type typeOfSrc,
JsonSerializationContext context) {
return new JsonPrimitive("registeredSerializer");
}
Expand All @@ -107,7 +107,7 @@ public JsonElement serialize(A src, Type typeOfSrc,
*/
public void testRegisteredDeserializerOverridesJsonAdapter() {
JsonDeserializer<A> deserializer = new JsonDeserializer<A>() {
public A deserialize(JsonElement json, Type typeOfT,
@Override public A deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
return new A("registeredDeserializer");
}
Expand Down
6 changes: 3 additions & 3 deletions gson/src/test/java/com/google/gson/functional/MapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void testMapStandardSubclassDeserialization() {

public void testMapSubclassDeserialization() {
Gson gson = new GsonBuilder().registerTypeAdapter(MyMap.class, new InstanceCreator<MyMap>() {
public MyMap createInstance(Type type) {
@Override public MyMap createInstance(Type type) {
return new MyMap();
}
}).create();
Expand All @@ -299,7 +299,7 @@ public void testCustomSerializerForSpecificMapType() {
null, Map.class, String.class, Long.class);
Gson gson = new GsonBuilder()
.registerTypeAdapter(type, new JsonSerializer<Map<String, Long>>() {
public JsonElement serialize(Map<String, Long> src, Type typeOfSrc,
@Override public JsonElement serialize(Map<String, Long> src, Type typeOfSrc,
JsonSerializationContext context) {
JsonArray array = new JsonArray();
for (long value : src.values()) {
Expand Down Expand Up @@ -493,7 +493,7 @@ public final void testInterfaceTypeMapWithSerializer() {
+ "\"subs\":{\"Test\":" + subTypeJson + "}}";

JsonSerializer<TestTypes.Base> baseTypeAdapter = new JsonSerializer<TestTypes.Base>() {
public JsonElement serialize(TestTypes.Base src, Type typeOfSrc,
@Override public JsonElement serialize(TestTypes.Base src, Type typeOfSrc,
JsonSerializationContext context) {
return baseTypeJsonElement;
}
Expand Down
4 changes: 2 additions & 2 deletions gson/src/test/java/com/google/gson/functional/ObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void testAnonymousLocalClassesCustomSerialization() throws Exception {
gson = new GsonBuilder()
.registerTypeHierarchyAdapter(ClassWithNoFields.class,
new JsonSerializer<ClassWithNoFields>() {
public JsonElement serialize(
@Override public JsonElement serialize(
ClassWithNoFields src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonObject();
}
Expand Down Expand Up @@ -342,7 +342,7 @@ public void testInnerClassDeserialization() {
final Parent p = new Parent();
Gson gson = new GsonBuilder().registerTypeAdapter(
Parent.Child.class, new InstanceCreator<Parent.Child>() {
public Parent.Child createInstance(Type type) {
@Override public Parent.Child createInstance(Type type) {
return p.new Child();
}
}).create();
Expand Down
Loading

0 comments on commit 7337057

Please sign in to comment.