diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..02ecaddc --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,46 @@ +# Based on default config generated by GitHub, see also https://github.com/github/codeql-action + +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + schedule: + # Run every Monday at 16:10 + - cron: '10 16 * * 1' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'java' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # Run all security queries and maintainability and reliability queries + queries: +security-and-quality + + # Only compile main sources, but ignore test sources because findings for them might not + # be that relevant (though GitHub security view also allows filtering by source type) + # Can replace this with github/codeql-action/autobuild action to run complete build + - name: Compile sources + run: | + mvn compile + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/extras/src/main/java/com/google/gson/interceptors/InterceptorFactory.java b/extras/src/main/java/com/google/gson/interceptors/InterceptorFactory.java index 907fca3a..4ea80c9b 100644 --- a/extras/src/main/java/com/google/gson/interceptors/InterceptorFactory.java +++ b/extras/src/main/java/com/google/gson/interceptors/InterceptorFactory.java @@ -12,7 +12,7 @@ import java.io.IOException; * A type adapter factory that implements {@code @Intercept}. */ public final class InterceptorFactory implements TypeAdapterFactory { - public TypeAdapter create(Gson gson, TypeToken type) { + @Override public TypeAdapter create(Gson gson, TypeToken type) { Intercept intercept = type.getRawType().getAnnotation(Intercept.class); if (intercept == null) { return null; diff --git a/extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java b/extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java index 0aab6598..39d618a5 100644 --- a/extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java +++ b/extras/src/test/java/com/google/gson/interceptors/InterceptorTest.java @@ -141,7 +141,7 @@ public final class InterceptorTest extends TestCase { } public static final class UserValidator implements JsonPostDeserializer { - 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."); } @@ -161,7 +161,7 @@ public final class InterceptorTest extends TestCase { } public static final class AddressValidator implements JsonPostDeserializer
{ - 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."); } diff --git a/extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java b/extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java index 7bd0a520..e3574bbc 100644 --- a/extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java +++ b/extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java @@ -70,6 +70,7 @@ public class PostConstructAdapterFactoryTest extends TestCase { } } + @Override public boolean equals(Object o) { if (o == this) { return true; @@ -95,6 +96,7 @@ public class PostConstructAdapterFactoryTest extends TestCase { this.sandwiches = sandwiches; } + @Override public boolean equals(Object o) { if (o == this) { return true; diff --git a/extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java b/extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java index 56e54290..fe4104fb 100644 --- a/extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java +++ b/extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java @@ -16,18 +16,16 @@ package com.google.gson.typeadapters; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; - -import com.google.gson.JsonParseException; import junit.framework.TestCase; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - public final class UtcDateTypeAdapterTest extends TestCase { private final Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new UtcDateTypeAdapter()) @@ -83,7 +81,7 @@ public final class UtcDateTypeAdapterTest extends TestCase { gson.fromJson("2017-06-20T14:32:30", Date.class); fail("No exception"); } catch (JsonParseException exe) { - assertEquals(exe.getMessage(), "java.text.ParseException: Failed to parse date ['2017-06-20T14']: 2017-06-20T14"); + assertEquals("java.text.ParseException: Failed to parse date ['2017-06-20T14']: 2017-06-20T14", exe.getMessage()); } } } diff --git a/gson/src/main/java/com/google/gson/JsonArray.java b/gson/src/main/java/com/google/gson/JsonArray.java index f5ed713c..68f503db 100644 --- a/gson/src/main/java/com/google/gson/JsonArray.java +++ b/gson/src/main/java/com/google/gson/JsonArray.java @@ -187,6 +187,7 @@ public final class JsonArray extends JsonElement implements Iterable iterator() { return elements.iterator(); } @@ -341,13 +342,12 @@ public final class JsonArray extends JsonElement implements Iterable { * @since 1.4 */ public JsonStreamParser(String json) { - this(new StringReader(json)); + this(new StringReader(json)); } /** @@ -81,6 +81,7 @@ public final class JsonStreamParser implements Iterator { * @throws NoSuchElementException if no {@code JsonElement} is available. * @since 1.4 */ + @Override public JsonElement next() throws JsonParseException { if (!hasNext()) { throw new NoSuchElementException(); @@ -103,6 +104,7 @@ public final class JsonStreamParser implements Iterator { * @throws JsonSyntaxException if the incoming stream is malformed JSON. * @since 1.4 */ + @Override public boolean hasNext() { synchronized (lock) { try { @@ -120,6 +122,7 @@ public final class JsonStreamParser implements Iterator { * implemented. * @since 1.4 */ + @Override public void remove() { throw new UnsupportedOperationException(); } diff --git a/gson/src/main/java/com/google/gson/internal/$Gson$Types.java b/gson/src/main/java/com/google/gson/internal/$Gson$Types.java index 32a84565..ee9cc72d 100644 --- a/gson/src/main/java/com/google/gson/internal/$Gson$Types.java +++ b/gson/src/main/java/com/google/gson/internal/$Gson$Types.java @@ -505,15 +505,15 @@ public final class $Gson$Types { } } - 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; } @@ -552,7 +552,7 @@ public final class $Gson$Types { this.componentType = canonicalize(componentType); } - public Type getGenericComponentType() { + @Override public Type getGenericComponentType() { return componentType; } @@ -601,11 +601,11 @@ public final class $Gson$Types { } } - 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; } diff --git a/gson/src/main/java/com/google/gson/internal/Excluder.java b/gson/src/main/java/com/google/gson/internal/Excluder.java index 9e7f3221..8cea6cf8 100644 --- a/gson/src/main/java/com/google/gson/internal/Excluder.java +++ b/gson/src/main/java/com/google/gson/internal/Excluder.java @@ -108,7 +108,7 @@ public final class Excluder implements TypeAdapterFactory, Cloneable { return result; } - public TypeAdapter create(final Gson gson, final TypeToken type) { + @Override public TypeAdapter create(final Gson gson, final TypeToken type) { Class rawType = type.getRawType(); boolean excludeClass = excludeClassChecks(rawType); diff --git a/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java b/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java index aaa8ce09..3be43689 100644 --- a/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java +++ b/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java @@ -41,7 +41,7 @@ import java.util.Set; public final class LinkedTreeMap extends AbstractMap implements Serializable { @SuppressWarnings({ "unchecked", "rawtypes" }) // to avoid Comparable>> private static final Comparator NATURAL_ORDER = new Comparator() { - public int compare(Comparable a, Comparable b) { + @Override public int compare(Comparable a, Comparable b) { return a.compareTo(b); } }; @@ -466,15 +466,15 @@ public final class LinkedTreeMap extends AbstractMap implements Seri 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; @@ -534,7 +534,7 @@ public final class LinkedTreeMap extends AbstractMap implements Seri LinkedTreeMapIterator() { } - public final boolean hasNext() { + @Override public final boolean hasNext() { return next != header; } @@ -550,7 +550,7 @@ public final class LinkedTreeMap extends AbstractMap implements Seri return lastReturned = e; } - public final void remove() { + @Override public final void remove() { if (lastReturned == null) { throw new IllegalStateException(); } @@ -567,7 +567,7 @@ public final class LinkedTreeMap extends AbstractMap implements Seri @Override public Iterator> iterator() { return new LinkedTreeMapIterator>() { - public Entry next() { + @Override public Entry next() { return nextNode(); } }; @@ -602,7 +602,7 @@ public final class LinkedTreeMap extends AbstractMap implements Seri @Override public Iterator iterator() { return new LinkedTreeMapIterator() { - public K next() { + @Override public K next() { return nextNode().key; } }; diff --git a/gson/src/main/java/com/google/gson/internal/Streams.java b/gson/src/main/java/com/google/gson/internal/Streams.java index ac99910a..0bb73aa1 100644 --- a/gson/src/main/java/com/google/gson/internal/Streams.java +++ b/gson/src/main/java/com/google/gson/internal/Streams.java @@ -105,13 +105,13 @@ public final class Streams { */ 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); } } diff --git a/gson/src/main/java/com/google/gson/stream/JsonReader.java b/gson/src/main/java/com/google/gson/stream/JsonReader.java index 3eb38b70..f722490e 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonReader.java +++ b/gson/src/main/java/com/google/gson/stream/JsonReader.java @@ -1212,7 +1212,7 @@ public class JsonReader implements Closeable { /** * 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; diff --git a/gson/src/main/java/com/google/gson/stream/JsonWriter.java b/gson/src/main/java/com/google/gson/stream/JsonWriter.java index 53e72513..476da2bb 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonWriter.java +++ b/gson/src/main/java/com/google/gson/stream/JsonWriter.java @@ -571,7 +571,7 @@ public class JsonWriter implements Closeable, Flushable { * 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."); } @@ -583,7 +583,7 @@ public class JsonWriter implements Closeable, Flushable { * * @throws IOException if the JSON document is incomplete. */ - public void close() throws IOException { + @Override public void close() throws IOException { out.close(); int size = stackSize; diff --git a/gson/src/test/java/com/google/gson/GsonTypeAdapterTest.java b/gson/src/test/java/com/google/gson/GsonTypeAdapterTest.java index decb93d8..2e00dc9b 100644 --- a/gson/src/test/java/com/google/gson/GsonTypeAdapterTest.java +++ b/gson/src/test/java/com/google/gson/GsonTypeAdapterTest.java @@ -130,7 +130,7 @@ public class GsonTypeAdapterTest extends TestCase { private void assertSerialized(String expected, Class instanceType, boolean registerAbstractDeserializer, boolean registerAbstractHierarchyDeserializer, Object instance) { JsonDeserializer deserializer = new JsonDeserializer() { - public Abstract deserialize(JsonElement json, Type typeOfT, + @Override public Abstract deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { throw new AssertionError(); } diff --git a/gson/src/test/java/com/google/gson/functional/CircularReferenceTest.java b/gson/src/test/java/com/google/gson/functional/CircularReferenceTest.java index d352e241..6c496237 100644 --- a/gson/src/test/java/com/google/gson/functional/CircularReferenceTest.java +++ b/gson/src/test/java/com/google/gson/functional/CircularReferenceTest.java @@ -79,7 +79,7 @@ public class CircularReferenceTest extends TestCase { ClassWithSelfReference obj = new ClassWithSelfReference(); obj.child = obj; Gson gson = new GsonBuilder().registerTypeAdapter(ClassWithSelfReference.class, new JsonSerializer() { - 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"); diff --git a/gson/src/test/java/com/google/gson/functional/CollectionTest.java b/gson/src/test/java/com/google/gson/functional/CollectionTest.java index 261c5d02..8d831a63 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -328,7 +328,7 @@ public class CollectionTest extends TestCase { public void testUserCollectionTypeAdapter() { Type listOfString = new TypeToken>() {}.getType(); Object stringListSerializer = new JsonSerializer>() { - public JsonElement serialize(List src, Type typeOfSrc, + @Override public JsonElement serialize(List src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src.get(0) + ";" + src.get(1)); } diff --git a/gson/src/test/java/com/google/gson/functional/ConcurrencyTest.java b/gson/src/test/java/com/google/gson/functional/ConcurrencyTest.java index 2dccf4b6..318c6ac3 100644 --- a/gson/src/test/java/com/google/gson/functional/ConcurrencyTest.java +++ b/gson/src/test/java/com/google/gson/functional/ConcurrencyTest.java @@ -71,7 +71,7 @@ public class ConcurrencyTest extends TestCase { 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(); @@ -102,7 +102,7 @@ public class ConcurrencyTest extends TestCase { 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++) { diff --git a/gson/src/test/java/com/google/gson/functional/CustomSerializerTest.java b/gson/src/test/java/com/google/gson/functional/CustomSerializerTest.java index c8095463..e04cb67c 100644 --- a/gson/src/test/java/com/google/gson/functional/CustomSerializerTest.java +++ b/gson/src/test/java/com/google/gson/functional/CustomSerializerTest.java @@ -91,7 +91,7 @@ public class CustomSerializerTest extends TestCase { public void testSerializerReturnsNull() { Gson gson = new GsonBuilder() .registerTypeAdapter(Base.class, new JsonSerializer() { - public JsonElement serialize(Base src, Type typeOfSrc, JsonSerializationContext context) { + @Override public JsonElement serialize(Base src, Type typeOfSrc, JsonSerializationContext context) { return null; } }) diff --git a/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java b/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java index 1f9c75cd..154bbc0a 100644 --- a/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java +++ b/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java @@ -470,7 +470,7 @@ public class DefaultTypeAdaptersTest extends TestCase { Gson gson = new GsonBuilder() .setDateFormat(pattern) .registerTypeAdapter(Date.class, new JsonDeserializer() { - public Date deserialize(JsonElement json, Type typeOfT, + @Override public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return new Date(1315806903103L); diff --git a/gson/src/test/java/com/google/gson/functional/GsonVersionDiagnosticsTest.java b/gson/src/test/java/com/google/gson/functional/GsonVersionDiagnosticsTest.java index 36eff8e1..aa6f4ccb 100644 --- a/gson/src/test/java/com/google/gson/functional/GsonVersionDiagnosticsTest.java +++ b/gson/src/test/java/com/google/gson/functional/GsonVersionDiagnosticsTest.java @@ -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() { @Override public void write(JsonWriter out, TestType value) { diff --git a/gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnClassesTest.java b/gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnClassesTest.java index 4288bfe3..db939dcd 100644 --- a/gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnClassesTest.java +++ b/gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnClassesTest.java @@ -88,7 +88,7 @@ public final class JsonAdapterAnnotationOnClassesTest extends TestCase { */ public void testRegisteredSerializerOverridesJsonAdapter() { JsonSerializer serializer = new JsonSerializer() { - public JsonElement serialize(A src, Type typeOfSrc, + @Override public JsonElement serialize(A src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive("registeredSerializer"); } @@ -107,7 +107,7 @@ public final class JsonAdapterAnnotationOnClassesTest extends TestCase { */ public void testRegisteredDeserializerOverridesJsonAdapter() { JsonDeserializer deserializer = new JsonDeserializer() { - public A deserialize(JsonElement json, Type typeOfT, + @Override public A deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return new A("registeredDeserializer"); } diff --git a/gson/src/test/java/com/google/gson/functional/MapTest.java b/gson/src/test/java/com/google/gson/functional/MapTest.java index d14585b3..602ff591 100644 --- a/gson/src/test/java/com/google/gson/functional/MapTest.java +++ b/gson/src/test/java/com/google/gson/functional/MapTest.java @@ -284,7 +284,7 @@ public class MapTest extends TestCase { public void testMapSubclassDeserialization() { Gson gson = new GsonBuilder().registerTypeAdapter(MyMap.class, new InstanceCreator() { - public MyMap createInstance(Type type) { + @Override public MyMap createInstance(Type type) { return new MyMap(); } }).create(); @@ -299,7 +299,7 @@ public class MapTest extends TestCase { null, Map.class, String.class, Long.class); Gson gson = new GsonBuilder() .registerTypeAdapter(type, new JsonSerializer>() { - public JsonElement serialize(Map src, Type typeOfSrc, + @Override public JsonElement serialize(Map src, Type typeOfSrc, JsonSerializationContext context) { JsonArray array = new JsonArray(); for (long value : src.values()) { @@ -493,7 +493,7 @@ public class MapTest extends TestCase { + "\"subs\":{\"Test\":" + subTypeJson + "}}"; JsonSerializer baseTypeAdapter = new JsonSerializer() { - public JsonElement serialize(TestTypes.Base src, Type typeOfSrc, + @Override public JsonElement serialize(TestTypes.Base src, Type typeOfSrc, JsonSerializationContext context) { return baseTypeJsonElement; } diff --git a/gson/src/test/java/com/google/gson/functional/ObjectTest.java b/gson/src/test/java/com/google/gson/functional/ObjectTest.java index 9fcbd311..6222cc2d 100644 --- a/gson/src/test/java/com/google/gson/functional/ObjectTest.java +++ b/gson/src/test/java/com/google/gson/functional/ObjectTest.java @@ -298,7 +298,7 @@ public class ObjectTest extends TestCase { gson = new GsonBuilder() .registerTypeHierarchyAdapter(ClassWithNoFields.class, new JsonSerializer() { - public JsonElement serialize( + @Override public JsonElement serialize( ClassWithNoFields src, Type typeOfSrc, JsonSerializationContext context) { return new JsonObject(); } @@ -342,7 +342,7 @@ public class ObjectTest extends TestCase { final Parent p = new Parent(); Gson gson = new GsonBuilder().registerTypeAdapter( Parent.Child.class, new InstanceCreator() { - public Parent.Child createInstance(Type type) { + @Override public Parent.Child createInstance(Type type) { return p.new Child(); } }).create(); diff --git a/gson/src/test/java/com/google/gson/functional/StreamingTypeAdaptersTest.java b/gson/src/test/java/com/google/gson/functional/StreamingTypeAdaptersTest.java index 45e85342..cbe339a9 100644 --- a/gson/src/test/java/com/google/gson/functional/StreamingTypeAdaptersTest.java +++ b/gson/src/test/java/com/google/gson/functional/StreamingTypeAdaptersTest.java @@ -155,7 +155,7 @@ public final class StreamingTypeAdaptersTest extends TestCase { String[] values = in.nextString().split(","); return new Person(values[0], Integer.parseInt(values[1])); } - public void write(JsonWriter out, Person person) throws IOException { + @Override public void write(JsonWriter out, Person person) throws IOException { out.value(person.name + "," + person.age); } }; diff --git a/gson/src/test/java/com/google/gson/internal/bind/RecursiveTypesResolveTest.java b/gson/src/test/java/com/google/gson/internal/bind/RecursiveTypesResolveTest.java index a2bece26..ca068df3 100644 --- a/gson/src/test/java/com/google/gson/internal/bind/RecursiveTypesResolveTest.java +++ b/gson/src/test/java/com/google/gson/internal/bind/RecursiveTypesResolveTest.java @@ -21,9 +21,6 @@ import com.google.gson.TypeAdapter; import com.google.gson.internal.$Gson$Types; import junit.framework.TestCase; -import java.io.PrintStream; -import java.lang.ref.WeakReference; - /** * Test fixes for infinite recursion on {@link $Gson$Types#resolve(java.lang.reflect.Type, Class, * java.lang.reflect.Type)}, described at Issue #440 diff --git a/metrics/src/main/java/com/google/gson/metrics/ParseBenchmark.java b/metrics/src/main/java/com/google/gson/metrics/ParseBenchmark.java index cc228e87..c00dbdcf 100644 --- a/metrics/src/main/java/com/google/gson/metrics/ParseBenchmark.java +++ b/metrics/src/main/java/com/google/gson/metrics/ParseBenchmark.java @@ -19,6 +19,7 @@ package com.google.gson.metrics; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonFactoryBuilder; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MapperFeature; @@ -224,7 +225,8 @@ public final class ParseBenchmark { com.fasterxml.jackson.core.JsonParser jp = jsonFactory.createParser(new CharArrayReader(data)); int depth = 0; do { - switch (jp.nextToken()) { + JsonToken token = jp.nextToken(); + switch (token) { case START_OBJECT: case START_ARRAY: depth++; @@ -243,6 +245,15 @@ public final class ParseBenchmark { case VALUE_NUMBER_FLOAT: jp.getLongValue(); break; + case VALUE_TRUE: + case VALUE_FALSE: + jp.getBooleanValue(); + break; + case VALUE_NULL: + // Do nothing; nextToken() will advance in stream + break; + default: + throw new IllegalArgumentException("Unexpected token " + token); } } while (depth > 0); jp.close(); diff --git a/proto/pom.xml b/proto/pom.xml index d4b60191..331eb593 100644 --- a/proto/pom.xml +++ b/proto/pom.xml @@ -75,7 +75,6 @@ - compile test-compile diff --git a/proto/src/main/proto/annotations.proto b/proto/src/test/proto/annotations.proto similarity index 100% rename from proto/src/main/proto/annotations.proto rename to proto/src/test/proto/annotations.proto diff --git a/proto/src/main/proto/bag.proto b/proto/src/test/proto/bag.proto similarity index 100% rename from proto/src/main/proto/bag.proto rename to proto/src/test/proto/bag.proto