From e2296f42d553e3f299c7dd2f4d1a4efd60007ade Mon Sep 17 00:00:00 2001 From: Mike Cumings Date: Tue, 25 Sep 2018 16:09:48 -0700 Subject: [PATCH 01/45] Fix issue with recursive type variable protections to fix #1390 When a type variable is referenced multiple times it needs to resolve to the same value. Previously, the second attempt would abort resolution early in order to protect against infinite recursion. --- .../com/google/gson/internal/$Gson$Types.java | 53 ++++++++++++------ .../ReusedTypeVariablesFullyResolveTest.java | 54 +++++++++++++++++++ 2 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java 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 adea605f..42344200 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 @@ -25,7 +25,12 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.lang.reflect.WildcardType; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Properties; import static com.google.gson.internal.$Gson$Preconditions.checkArgument; import static com.google.gson.internal.$Gson$Preconditions.checkNotNull; @@ -334,41 +339,50 @@ public final class $Gson$Types { } public static Type resolve(Type context, Class contextRawType, Type toResolve) { - return resolve(context, contextRawType, toResolve, new HashSet()); + return resolve(context, contextRawType, toResolve, new HashMap()); } private static Type resolve(Type context, Class contextRawType, Type toResolve, - Collection visitedTypeVariables) { + Map visitedTypeVariables) { // this implementation is made a little more complicated in an attempt to avoid object-creation + TypeVariable resolving = null; while (true) { if (toResolve instanceof TypeVariable) { TypeVariable typeVariable = (TypeVariable) toResolve; - if (visitedTypeVariables.contains(typeVariable)) { + Type previouslyResolved = visitedTypeVariables.get(typeVariable); + if (previouslyResolved != null) { // cannot reduce due to infinite recursion - return toResolve; - } else { - visitedTypeVariables.add(typeVariable); + return (previouslyResolved == Void.TYPE) ? toResolve : previouslyResolved; } + + // Insert a placeholder to mark the fact that we are in the process of resolving this type + visitedTypeVariables.put(typeVariable, Void.TYPE); + if (resolving == null) { + resolving = typeVariable; + } + toResolve = resolveTypeVariable(context, contextRawType, typeVariable); if (toResolve == typeVariable) { - return toResolve; + break; } } else if (toResolve instanceof Class && ((Class) toResolve).isArray()) { Class original = (Class) toResolve; Type componentType = original.getComponentType(); Type newComponentType = resolve(context, contextRawType, componentType, visitedTypeVariables); - return componentType == newComponentType + toResolve = componentType == newComponentType ? original : arrayOf(newComponentType); + break; } else if (toResolve instanceof GenericArrayType) { GenericArrayType original = (GenericArrayType) toResolve; Type componentType = original.getGenericComponentType(); Type newComponentType = resolve(context, contextRawType, componentType, visitedTypeVariables); - return componentType == newComponentType + toResolve = componentType == newComponentType ? original : arrayOf(newComponentType); + break; } else if (toResolve instanceof ParameterizedType) { ParameterizedType original = (ParameterizedType) toResolve; @@ -388,9 +402,10 @@ public final class $Gson$Types { } } - return changed + toResolve = changed ? newParameterizedTypeWithOwner(newOwnerType, original.getRawType(), args) : original; + break; } else if (toResolve instanceof WildcardType) { WildcardType original = (WildcardType) toResolve; @@ -400,20 +415,28 @@ public final class $Gson$Types { if (originalLowerBound.length == 1) { Type lowerBound = resolve(context, contextRawType, originalLowerBound[0], visitedTypeVariables); if (lowerBound != originalLowerBound[0]) { - return supertypeOf(lowerBound); + toResolve = supertypeOf(lowerBound); + break; } } else if (originalUpperBound.length == 1) { Type upperBound = resolve(context, contextRawType, originalUpperBound[0], visitedTypeVariables); if (upperBound != originalUpperBound[0]) { - return subtypeOf(upperBound); + toResolve = subtypeOf(upperBound); + break; } } - return original; + toResolve = original; + break; } else { - return toResolve; + break; } } + // ensure that any in-process resolution gets updated with the final result + if (resolving != null) { + visitedTypeVariables.put(resolving, toResolve); + } + return toResolve; } static Type resolveTypeVariable(Type context, Class contextRawType, TypeVariable unknown) { diff --git a/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java b/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java new file mode 100644 index 00000000..e3ddd840 --- /dev/null +++ b/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java @@ -0,0 +1,54 @@ +package com.google.gson.functional; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import static org.junit.Assert.*; + +/** + * This test covers the scenario described in #1390 where a type variable needs to be used + * by a type definition multiple times. Both type variable references should resolve to the + * same underlying concrete type. + */ +public class ReusedTypeVariablesFullyResolveTest { + + private Gson gson; + + @Before + public void setUp() { + gson = new GsonBuilder().create(); + } + + @SuppressWarnings("ConstantConditions") // The instances were being unmarshaled as Strings instead of TestEnums + @Test + public void testGenericsPreservation() { + TestEnumSetCollection withSet = gson.fromJson("{\"collection\":[\"ONE\",\"THREE\"]}", TestEnumSetCollection.class); + Iterator iterator = withSet.collection.iterator(); + assertNotNull(withSet); + assertNotNull(withSet.collection); + assertEquals(2, withSet.collection.size()); + TestEnum first = iterator.next(); + TestEnum second = iterator.next(); + + assertTrue(first instanceof TestEnum); + assertTrue(second instanceof TestEnum); + } + + enum TestEnum { ONE, TWO, THREE } + + private static class TestEnumSetCollection extends SetCollection {} + + private static class SetCollection extends BaseCollection> {} + + private static class BaseCollection> + { + public C collection; + } + +} From 69f7c4e243c385b318ed63205817347e4bbe379e Mon Sep 17 00:00:00 2001 From: Mike Cumings Date: Wed, 26 Sep 2018 22:38:53 -0700 Subject: [PATCH 02/45] Replace instance equality checks in $Gson$Types#resolve --- .../main/java/com/google/gson/internal/$Gson$Types.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 42344200..53985bc3 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 @@ -370,7 +370,7 @@ public final class $Gson$Types { Class original = (Class) toResolve; Type componentType = original.getComponentType(); Type newComponentType = resolve(context, contextRawType, componentType, visitedTypeVariables); - toResolve = componentType == newComponentType + toResolve = equal(componentType, newComponentType) ? original : arrayOf(newComponentType); break; @@ -379,7 +379,7 @@ public final class $Gson$Types { GenericArrayType original = (GenericArrayType) toResolve; Type componentType = original.getGenericComponentType(); Type newComponentType = resolve(context, contextRawType, componentType, visitedTypeVariables); - toResolve = componentType == newComponentType + toResolve = equal(componentType, newComponentType) ? original : arrayOf(newComponentType); break; @@ -388,12 +388,12 @@ public final class $Gson$Types { ParameterizedType original = (ParameterizedType) toResolve; Type ownerType = original.getOwnerType(); Type newOwnerType = resolve(context, contextRawType, ownerType, visitedTypeVariables); - boolean changed = newOwnerType != ownerType; + boolean changed = !equal(newOwnerType, ownerType); Type[] args = original.getActualTypeArguments(); for (int t = 0, length = args.length; t < length; t++) { Type resolvedTypeArgument = resolve(context, contextRawType, args[t], visitedTypeVariables); - if (resolvedTypeArgument != args[t]) { + if (!equal(resolvedTypeArgument, args[t])) { if (!changed) { args = args.clone(); changed = true; From 9171715a880bf65bb698c6c76480d0a3fe65ae20 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Sun, 3 May 2020 00:34:08 +0200 Subject: [PATCH 03/45] Fix ISO8601UtilsTest failing on systems with UTC+X Previously ISO8601UtilsTest.testDateFormatString() would fail on systems where the time zone is UTC+X because getTime() returned "2018-06-24" for them. Additionally the tests which previously changed the system locale and time zone have been rewritten to create a UTC calendar instead. Setting locale seems to not be necessary because ISO8601Utils.parse(...) does not do that either. --- .../internal/bind/util/ISO8601UtilsTest.java | 71 +++++++++---------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/gson/src/test/java/com/google/gson/internal/bind/util/ISO8601UtilsTest.java b/gson/src/test/java/com/google/gson/internal/bind/util/ISO8601UtilsTest.java index 10b7b5e0..1c6c69c0 100644 --- a/gson/src/test/java/com/google/gson/internal/bind/util/ISO8601UtilsTest.java +++ b/gson/src/test/java/com/google/gson/internal/bind/util/ISO8601UtilsTest.java @@ -15,9 +15,25 @@ public class ISO8601UtilsTest { @Rule public final ExpectedException exception = ExpectedException.none(); + private static TimeZone utcTimeZone() { + return TimeZone.getTimeZone("UTC"); + } + + private static GregorianCalendar createUtcCalendar() { + TimeZone utc = utcTimeZone(); + GregorianCalendar calendar = new GregorianCalendar(utc); + // Calendar was created with current time, must clear it + calendar.clear(); + return calendar; + } + @Test public void testDateFormatString() { - Date date = new GregorianCalendar(2018, Calendar.JUNE, 25).getTime(); + GregorianCalendar calendar = new GregorianCalendar(utcTimeZone(), Locale.US); + // Calendar was created with current time, must clear it + calendar.clear(); + calendar.set(2018, Calendar.JUNE, 25); + Date date = calendar.getTime(); String dateStr = ISO8601Utils.format(date); String expectedDate = "2018-06-25"; assertEquals(expectedDate, dateStr.substring(0, expectedDate.length())); @@ -51,51 +67,28 @@ public class ISO8601UtilsTest { @Test public void testDateParseWithTimezone() throws ParseException { - TimeZone defaultTimeZone = TimeZone.getDefault(); - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - Locale defaultLocale = Locale.getDefault(); - Locale.setDefault(Locale.US); - try { - String dateStr = "2018-06-25T00:00:00-03:00"; - Date date = ISO8601Utils.parse(dateStr, new ParsePosition(0)); - Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 3, 0).getTime(); - assertEquals(expectedDate, date); - } finally { - TimeZone.setDefault(defaultTimeZone); - Locale.setDefault(defaultLocale); - } + String dateStr = "2018-06-25T00:00:00-03:00"; + Date date = ISO8601Utils.parse(dateStr, new ParsePosition(0)); + GregorianCalendar calendar = createUtcCalendar(); + calendar.set(2018, Calendar.JUNE, 25, 3, 0); + Date expectedDate = calendar.getTime(); + assertEquals(expectedDate, date); } @Test public void testDateParseSpecialTimezone() throws ParseException { - TimeZone defaultTimeZone = TimeZone.getDefault(); - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - Locale defaultLocale = Locale.getDefault(); - Locale.setDefault(Locale.US); - try { - String dateStr = "2018-06-25T00:02:00-02:58"; - Date date = ISO8601Utils.parse(dateStr, new ParsePosition(0)); - Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 3, 0).getTime(); - assertEquals(expectedDate, date); - } finally { - TimeZone.setDefault(defaultTimeZone); - Locale.setDefault(defaultLocale); - } + String dateStr = "2018-06-25T00:02:00-02:58"; + Date date = ISO8601Utils.parse(dateStr, new ParsePosition(0)); + GregorianCalendar calendar = createUtcCalendar(); + calendar.set(2018, Calendar.JUNE, 25, 3, 0); + Date expectedDate = calendar.getTime(); + assertEquals(expectedDate, date); } @Test public void testDateParseInvalidTime() throws ParseException { - TimeZone defaultTimeZone = TimeZone.getDefault(); - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - Locale defaultLocale = Locale.getDefault(); - Locale.setDefault(Locale.US); - try { - String dateStr = "2018-06-25T61:60:62-03:00"; - exception.expect(ParseException.class); - ISO8601Utils.parse(dateStr, new ParsePosition(0)); - } finally { - TimeZone.setDefault(defaultTimeZone); - Locale.setDefault(defaultLocale); - } + String dateStr = "2018-06-25T61:60:62-03:00"; + exception.expect(ParseException.class); + ISO8601Utils.parse(dateStr, new ParsePosition(0)); } } From ceae88bd6667f4263bbe02e6b3710b8a683906a2 Mon Sep 17 00:00:00 2001 From: Marius Volkhart Date: Wed, 13 May 2020 21:49:59 +0200 Subject: [PATCH 04/45] Update proguard.cfg (#1693) TypeAdapter is an abstract class, and R8 warns about this during the build. --- examples/android-proguard-example/proguard.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/android-proguard-example/proguard.cfg b/examples/android-proguard-example/proguard.cfg index 1a932cb9..e0e0a97f 100644 --- a/examples/android-proguard-example/proguard.cfg +++ b/examples/android-proguard-example/proguard.cfg @@ -15,7 +15,7 @@ # Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory, # JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) --keep class * implements com.google.gson.TypeAdapter +-keep class * extends com.google.gson.TypeAdapter -keep class * implements com.google.gson.TypeAdapterFactory -keep class * implements com.google.gson.JsonSerializer -keep class * implements com.google.gson.JsonDeserializer From b39494dbe68f91045850778cac4b661b38beb615 Mon Sep 17 00:00:00 2001 From: Richard Hernandez Date: Tue, 26 May 2020 20:12:06 -0700 Subject: [PATCH 05/45] Fix fallback behavior of UnsafeReflectionAllocator when AccessibleObject isn't so accessible --- .../reflect/UnsafeReflectionAccessor.java | 2 +- .../reflect/UnsafeReflectionAccessorTest.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gson/src/main/java/com/google/gson/internal/reflect/UnsafeReflectionAccessor.java b/gson/src/main/java/com/google/gson/internal/reflect/UnsafeReflectionAccessor.java index 749335b7..b23d7bab 100644 --- a/gson/src/main/java/com/google/gson/internal/reflect/UnsafeReflectionAccessor.java +++ b/gson/src/main/java/com/google/gson/internal/reflect/UnsafeReflectionAccessor.java @@ -79,7 +79,7 @@ final class UnsafeReflectionAccessor extends ReflectionAccessor { private static Field getOverrideField() { try { return AccessibleObject.class.getDeclaredField("override"); - } catch (NoSuchFieldException e) { + } catch (Exception e) { return null; } } diff --git a/gson/src/test/java/com/google/gson/internal/reflect/UnsafeReflectionAccessorTest.java b/gson/src/test/java/com/google/gson/internal/reflect/UnsafeReflectionAccessorTest.java index d5caaf53..b330e662 100644 --- a/gson/src/test/java/com/google/gson/internal/reflect/UnsafeReflectionAccessorTest.java +++ b/gson/src/test/java/com/google/gson/internal/reflect/UnsafeReflectionAccessorTest.java @@ -15,10 +15,12 @@ */ package com.google.gson.internal.reflect; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.lang.reflect.Field; +import java.security.Permission; import org.junit.Test; @@ -41,6 +43,30 @@ public class UnsafeReflectionAccessorTest { } } + @Test + public void testMakeAccessibleWithRestrictiveSecurityManager() throws Exception { + final Permission accessDeclaredMembers = new RuntimePermission("accessDeclaredMembers"); + final SecurityManager original = System.getSecurityManager(); + SecurityManager restrictiveManager = new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + if (accessDeclaredMembers.equals(perm)) { + throw new SecurityException("nope"); + } + } + }; + System.setSecurityManager(restrictiveManager); + + try { + UnsafeReflectionAccessor accessor = new UnsafeReflectionAccessor(); + Field field = ClassWithPrivateFinalFields.class.getDeclaredField("a"); + assertFalse("override field should have been inaccessible", accessor.makeAccessibleWithUnsafe(field)); + accessor.makeAccessible(field); + } finally { + System.setSecurityManager(original); + } + } + @SuppressWarnings("unused") private static final class ClassWithPrivateFinalFields { private final String a; From b1edb7048687c2822b4fa006ddeb5e2cc2a038f9 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Sat, 19 Sep 2020 13:30:50 +0200 Subject: [PATCH 06/45] Improve incorrect JsonStreamParser doc --- .../java/com/google/gson/JsonStreamParser.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gson/src/main/java/com/google/gson/JsonStreamParser.java b/gson/src/main/java/com/google/gson/JsonStreamParser.java index 1c0c9b9d..37075503 100644 --- a/gson/src/main/java/com/google/gson/JsonStreamParser.java +++ b/gson/src/main/java/com/google/gson/JsonStreamParser.java @@ -29,8 +29,9 @@ import com.google.gson.stream.MalformedJsonException; /** * A streaming parser that allows reading of multiple {@link JsonElement}s from the specified reader - * asynchronously. - * + * asynchronously. The JSON data is parsed in lenient mode, see also + * {@link JsonReader#setLenient(boolean)}. + * *

This class is conditionally thread-safe (see Item 70, Effective Java second edition). To * properly use this class across multiple threads, you will need to add some external * synchronization. For example: @@ -72,10 +73,12 @@ public final class JsonStreamParser implements Iterator { } /** - * Returns the next available {@link JsonElement} on the reader. Null if none available. - * - * @return the next available {@link JsonElement} on the reader. Null if none available. - * @throws JsonParseException if the incoming stream is malformed JSON. + * Returns the next available {@link JsonElement} on the reader. Throws a + * {@link NoSuchElementException} if no element is available. + * + * @return the next available {@code JsonElement} on the reader. + * @throws JsonSyntaxException if the incoming stream is malformed JSON. + * @throws NoSuchElementException if no {@code JsonElement} is available. * @since 1.4 */ public JsonElement next() throws JsonParseException { @@ -97,6 +100,7 @@ public final class JsonStreamParser implements Iterator { /** * Returns true if a {@link JsonElement} is available on the input for consumption * @return true if a {@link JsonElement} is available on the input, false otherwise + * @throws JsonSyntaxException if the incoming stream is malformed JSON. * @since 1.4 */ public boolean hasNext() { From 074a556d38f0ff2c7a4924bb00a8ae1631601b67 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 22:55:48 +0000 Subject: [PATCH 07/45] Bump junit from 3.8.2 to 4.13.1 in /extras Bumps [junit](https://github.com/junit-team/junit4) from 3.8.2 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md) - [Commits](https://github.com/junit-team/junit4/compare/r3.8.2...r4.13.1) Signed-off-by: dependabot[bot] --- extras/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/pom.xml b/extras/pom.xml index 1c5e76c3..9b74d1a1 100644 --- a/extras/pom.xml +++ b/extras/pom.xml @@ -51,7 +51,7 @@ junit junit - 3.8.2 + 4.13.1 test From 345dea2c8adc0af2722c4261e7e3fa93a1f9bd0c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 22:56:03 +0000 Subject: [PATCH 08/45] Bump junit from 4.12 to 4.13.1 in /proto Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1) Signed-off-by: dependabot[bot] --- proto/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/pom.xml b/proto/pom.xml index 99f7791d..3ce08bbe 100644 --- a/proto/pom.xml +++ b/proto/pom.xml @@ -76,7 +76,7 @@ junit junit - 4.12 + 4.13.1 test From daba2fd7ff4bc9fd51c209952964b6fd5366b923 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 22:56:05 +0000 Subject: [PATCH 09/45] Bump junit from 3.8.2 to 4.13.1 in /codegen Bumps [junit](https://github.com/junit-team/junit4) from 3.8.2 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md) - [Commits](https://github.com/junit-team/junit4/compare/r3.8.2...r4.13.1) Signed-off-by: dependabot[bot] --- codegen/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/pom.xml b/codegen/pom.xml index c2f9499a..cee611ab 100644 --- a/codegen/pom.xml +++ b/codegen/pom.xml @@ -40,7 +40,7 @@ junit junit - 3.8.2 + 4.13.1 test From ada6985285ee2d1d864c77d17d9b162d78371a26 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 22:56:23 +0000 Subject: [PATCH 10/45] Bump junit from 3.8.2 to 4.13.1 in /metrics Bumps [junit](https://github.com/junit-team/junit4) from 3.8.2 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md) - [Commits](https://github.com/junit-team/junit4/compare/r3.8.2...r4.13.1) Signed-off-by: dependabot[bot] --- metrics/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/pom.xml b/metrics/pom.xml index 9a084452..79641a55 100644 --- a/metrics/pom.xml +++ b/metrics/pom.xml @@ -51,7 +51,7 @@ junit junit - 3.8.2 + 4.13.1 test From bcb6b1fa812cb029bee27619c0a9fe01b89f88f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Thu, 13 May 2021 16:30:52 -0700 Subject: [PATCH 11/45] Create dependabot.yml --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..daec3189 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "maven" + directory: "/" + schedule: + interval: "daily" From 49d128b4231217786274a53df29af1aeeb469cdb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 May 2021 23:31:25 +0000 Subject: [PATCH 12/45] Bump maven-javadoc-plugin from 2.10.4 to 3.2.0 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 2.10.4 to 3.2.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-2.10.4...maven-javadoc-plugin-3.2.0) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1fb47fcd..02f2d4c6 100644 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.4 + 3.2.0 org.apache.maven.plugins From 0d4e59da8bad80b48b13d1be1728244e9faa99ac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 May 2021 23:31:25 +0000 Subject: [PATCH 13/45] Bump maven-bundle-plugin from 3.3.0 to 5.1.2 Bumps maven-bundle-plugin from 3.3.0 to 5.1.2. Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1fb47fcd..e8a715d0 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,7 @@ org.apache.felix maven-bundle-plugin - 3.3.0 + 5.1.2 true From 83c63d225604b2c1c4c863a18940a52cc7c70f2a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 May 2021 23:31:27 +0000 Subject: [PATCH 14/45] Bump bnd-maven-plugin from 4.0.0 to 5.3.0 Bumps [bnd-maven-plugin](https://github.com/bndtools/bnd) from 4.0.0 to 5.3.0. - [Release notes](https://github.com/bndtools/bnd/releases) - [Changelog](https://github.com/bndtools/bnd/blob/master/docs/ADDING_RELEASE_DOCS.md) - [Commits](https://github.com/bndtools/bnd/commits) Signed-off-by: dependabot[bot] --- gson/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gson/pom.xml b/gson/pom.xml index cf32962a..5388e22e 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -34,7 +34,7 @@ biz.aQute.bnd bnd-maven-plugin - 4.0.0 + 5.3.0 From e6750e7b947b5508128689915c66e89792e0cdb2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 May 2021 23:31:28 +0000 Subject: [PATCH 15/45] Bump maven-scm-provider-gitexe from 1.9.5 to 1.11.2 Bumps maven-scm-provider-gitexe from 1.9.5 to 1.11.2. Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1fb47fcd..af96a31f 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ org.apache.maven.scm maven-scm-provider-gitexe - 1.9.5 + 1.11.2 From 05a25a1ef242520bef0e4f9a64e319f3af687e69 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 May 2021 23:31:34 +0000 Subject: [PATCH 16/45] Bump junit from 4.12 to 4.13.2 Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.2. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.2) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1fb47fcd..14c5a2ca 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ junit junit - 4.12 + 4.13.2 test From d4fb033a472c338814f4159d6602aef561f393f1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 May 2021 06:27:14 +0000 Subject: [PATCH 17/45] Bump maven-javadoc-plugin from 3.2.0 to 3.3.0 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.2.0...maven-javadoc-plugin-3.3.0) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9a9f748f..ce9ec201 100644 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + 3.3.0 org.apache.maven.plugins From fa4a17756d0e54aaad6e8c33054ff64f8e74cd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Mon, 24 May 2021 15:37:40 -0700 Subject: [PATCH 18/45] Add missing dependency for the release plugin. --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index ce9ec201..a01cf18c 100644 --- a/pom.xml +++ b/pom.xml @@ -117,6 +117,11 @@ maven-release-plugin 2.5.3 + + org.apache.maven.scm + maven-scm-api + 1.11.2 + org.apache.maven.scm maven-scm-provider-gitexe From 4520489c29e770c64b11ca35e0a0fdf17a1874ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Mon, 24 May 2021 16:22:41 -0700 Subject: [PATCH 19/45] [maven-release-plugin] prepare release gson-parent-2.8.7 --- gson/pom.xml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gson/pom.xml b/gson/pom.xml index 5388e22e..7cdd0898 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -4,7 +4,7 @@ com.google.code.gson gson-parent - 2.8.7-SNAPSHOT + 2.8.7 gson diff --git a/pom.xml b/pom.xml index a01cf18c..2181df7f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.google.code.gson gson-parent - 2.8.7-SNAPSHOT + 2.8.7 pom Gson Parent @@ -31,7 +31,7 @@ https://github.com/google/gson/ scm:git:https://github.com/google/gson.git scm:git:git@github.com:google/gson.git - HEAD + gson-parent-2.8.7 From dadbdbb837dcff4bd0519c8977d6c3a3c959b438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Mon, 24 May 2021 16:22:45 -0700 Subject: [PATCH 20/45] [maven-release-plugin] prepare for next development iteration --- gson/pom.xml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gson/pom.xml b/gson/pom.xml index 7cdd0898..83f52b3a 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -4,7 +4,7 @@ com.google.code.gson gson-parent - 2.8.7 + 2.8.8-SNAPSHOT gson diff --git a/pom.xml b/pom.xml index 2181df7f..2a445fd2 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.google.code.gson gson-parent - 2.8.7 + 2.8.8-SNAPSHOT pom Gson Parent @@ -31,7 +31,7 @@ https://github.com/google/gson/ scm:git:https://github.com/google/gson.git scm:git:git@github.com:google/gson.git - gson-parent-2.8.7 + HEAD From 45c0bd96f08ce60baaacc339138a2a2c97b953a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Mon, 24 May 2021 16:39:52 -0700 Subject: [PATCH 21/45] Update user guide and change log to reflect 2.8.7 release. --- CHANGELOG.md | 10 ++++++++++ UserGuide.md | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f48e126b..98aa3ab0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ Change Log ========== +## Version 2.8.7 + +* Fixed `ISO8601UtilsTest` failing on systems with UTC+X. +* Improved javadoc for `JsonStreamParser`. +* Updated proguard.cfg (#1693). +* Fixed `IllegalStateException` in `JsonTreeWriter` (#1592). +* Added `JsonArray.isEmpty()` (#1640). +* Added new test cases (#1638). +* Fixed OSGi metadata generation to work on JavaSE < 9 (#1603). + ## Version 2.8.6 _2019-10-04_ [GitHub Diff](https://github.com/google/gson/compare/gson-parent-2.8.5...gson-parent-2.8.6) * Added static methods `JsonParser.parseString` and `JsonParser.parseReader` and deprecated instance method `JsonParser.parse` diff --git a/UserGuide.md b/UserGuide.md index ff9f48c3..22d4799d 100644 --- a/UserGuide.md +++ b/UserGuide.md @@ -74,7 +74,7 @@ The Gson instance does not maintain any state while invoking Json operations. So ## Using Gson with Gradle/Android ``` dependencies { - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.8.7' } ``` ## Using Gson with Maven @@ -86,7 +86,7 @@ To use Gson with Maven2/3, you can use the Gson version available in Maven Centr com.google.code.gson gson - 2.8.6 + 2.8.7 compile From 812b9c08e373240d69e0dd99a8d08fd47c53b48e Mon Sep 17 00:00:00 2001 From: Conclure <63319713+Conclure@users.noreply.github.com> Date: Wed, 26 May 2021 13:27:53 +0200 Subject: [PATCH 22/45] Update README.md version 2.8.6 -> 2.8.7 version 2.8.6 -> 2.8.7 for gradle and maven dependencies block --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e3d9a9a1..22ffdae5 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ There are a few open-source projects that can convert Java objects to JSON. Howe Gradle: ```gradle dependencies { - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.8.7' } ``` @@ -26,7 +26,7 @@ Maven: com.google.code.gson gson - 2.8.6 + 2.8.7 ``` From 55115a5ca259787ce8d4deb7952d198f50591f92 Mon Sep 17 00:00:00 2001 From: HiFromAjay Date: Fri, 11 Jun 2021 10:04:32 -0600 Subject: [PATCH 23/45] Test cases for testing the exceptional behavior of get, getAsBoolean, getAsDouble, getAsInt, getAsJsonArray, getAsJsonObject, getAsLong, and getAsString methods of JsonArray class. These test cases, which we wrote according to the specified behavior of each method, that helped us in identifying the documentation bugs in JsonArray and JsonElement classes, which we submitted issues for (Issue #1908). Note that we have adapted these test cases based on similar tests from the JSON-java project (https://github.com/stleary/JSON-java). --- .../java/com/google/gson/JsonArrayTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/gson/src/test/java/com/google/gson/JsonArrayTest.java b/gson/src/test/java/com/google/gson/JsonArrayTest.java index b77d6f1b..7ad4f5de 100644 --- a/gson/src/test/java/com/google/gson/JsonArrayTest.java +++ b/gson/src/test/java/com/google/gson/JsonArrayTest.java @@ -20,6 +20,9 @@ import junit.framework.TestCase; import com.google.gson.common.MoreAsserts; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * @author Jesse Wilson */ @@ -99,4 +102,65 @@ public final class JsonArrayTest extends TestCase { assertEquals(1, original.get(0).getAsJsonArray().size()); assertEquals(0, copy.get(0).getAsJsonArray().size()); } + + public void testFailedGetArrayValues() { + String arrayStr = "[" + "true," + "false," + "\"true\"," + "\"false\"," + "\"hello\"," + "23.45e-4," + "\"23.45\"," + "42," + "\"43\"," + "[" + "\"world\"" + "]," + "{" + "\"key1\":\"value1\"," + "\"key2\":\"value2\"," + "\"key3\":\"value3\"," + "\"key4\":\"value4\"" + "}," + "0," + "\"-1\"" + "]"; + JsonArray jsonArray = (JsonArray) JsonParser.parseString(arrayStr); + try { + jsonArray.get(10).getAsBoolean(); + assertTrue("expected getBoolean to fail", false); + } catch (UnsupportedOperationException e) { + assertEquals("Expected an exception message", + "JsonObject",e.getMessage()); + } + try { + jsonArray.get(-1); + assertTrue("expected get to fail", false); + } catch (IndexOutOfBoundsException e) { + assertEquals("Expected an exception message", + "Index -1 out of bounds for length 13",e.getMessage()); + } + try { + jsonArray.get(4).getAsDouble(); + assertTrue("expected getDouble to fail", false); + } catch (NumberFormatException e) { + assertEquals("Expected an exception message", + "For input string: \"hello\"",e.getMessage()); + } + try { + jsonArray.get(4).getAsInt(); + assertTrue("expected getInt to fail", false); + } catch (NumberFormatException e) { + assertEquals("Expected an exception message", + "For input string: \"hello\"",e.getMessage()); + } + try { + jsonArray.get(4).getAsJsonArray(); + assertTrue("expected getJSONArray to fail", false); + } catch (IllegalStateException e) { + assertEquals("Expected an exception message", + "Not a JSON Array: \"hello\"",e.getMessage()); + } + try { + jsonArray.get(4).getAsJsonObject(); + assertTrue("expected getJSONObject to fail", false); + } catch (IllegalStateException e) { + assertEquals("Expected an exception message", + "Not a JSON Object: \"hello\"",e.getMessage()); + } + try { + jsonArray.get(4).getAsLong(); + assertTrue("expected getLong to fail", false); + } catch (NumberFormatException e) { + assertEquals("Expected an exception message", + "For input string: \"hello\"",e.getMessage()); + } + try { + jsonArray.get(10).getAsString(); + assertTrue("expected getString to fail", false); + } catch (UnsupportedOperationException e) { + assertEquals("Expected an exception message", + "JsonObject",e.getMessage()); + } + } } From 2d1981d39bfcadfeac553582494abaec2fc5d737 Mon Sep 17 00:00:00 2001 From: HiFromAjay Date: Mon, 14 Jun 2021 14:31:14 -0600 Subject: [PATCH 24/45] modify test cases for testing the exceptional behavior of get... methods [use fail(...), use JsonArray methods, remove unused values, formatting, #1909, #1908] --- .../java/com/google/gson/JsonArrayTest.java | 95 ++++++++++--------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/gson/src/test/java/com/google/gson/JsonArrayTest.java b/gson/src/test/java/com/google/gson/JsonArrayTest.java index 7ad4f5de..86ef03c8 100644 --- a/gson/src/test/java/com/google/gson/JsonArrayTest.java +++ b/gson/src/test/java/com/google/gson/JsonArrayTest.java @@ -20,8 +20,8 @@ import junit.framework.TestCase; import com.google.gson.common.MoreAsserts; +import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; /** * @author Jesse Wilson @@ -104,63 +104,66 @@ public final class JsonArrayTest extends TestCase { } public void testFailedGetArrayValues() { - String arrayStr = "[" + "true," + "false," + "\"true\"," + "\"false\"," + "\"hello\"," + "23.45e-4," + "\"23.45\"," + "42," + "\"43\"," + "[" + "\"world\"" + "]," + "{" + "\"key1\":\"value1\"," + "\"key2\":\"value2\"," + "\"key3\":\"value3\"," + "\"key4\":\"value4\"" + "}," + "0," + "\"-1\"" + "]"; - JsonArray jsonArray = (JsonArray) JsonParser.parseString(arrayStr); + JsonArray jsonArray = new JsonArray(); + jsonArray.add(JsonParser.parseString("{" + "\"key1\":\"value1\"," + "\"key2\":\"value2\"," + "\"key3\":\"value3\"," + "\"key4\":\"value4\"" + "}")); try { - jsonArray.get(10).getAsBoolean(); - assertTrue("expected getBoolean to fail", false); + jsonArray.getAsBoolean(); + fail("expected getBoolean to fail"); } catch (UnsupportedOperationException e) { assertEquals("Expected an exception message", - "JsonObject",e.getMessage()); + "JsonObject", e.getMessage()); } try { jsonArray.get(-1); - assertTrue("expected get to fail", false); + fail("expected get to fail"); } catch (IndexOutOfBoundsException e) { assertEquals("Expected an exception message", - "Index -1 out of bounds for length 13",e.getMessage()); + "Index -1 out of bounds for length 1", e.getMessage()); } try { - jsonArray.get(4).getAsDouble(); - assertTrue("expected getDouble to fail", false); - } catch (NumberFormatException e) { - assertEquals("Expected an exception message", - "For input string: \"hello\"",e.getMessage()); - } - try { - jsonArray.get(4).getAsInt(); - assertTrue("expected getInt to fail", false); - } catch (NumberFormatException e) { - assertEquals("Expected an exception message", - "For input string: \"hello\"",e.getMessage()); - } - try { - jsonArray.get(4).getAsJsonArray(); - assertTrue("expected getJSONArray to fail", false); - } catch (IllegalStateException e) { - assertEquals("Expected an exception message", - "Not a JSON Array: \"hello\"",e.getMessage()); - } - try { - jsonArray.get(4).getAsJsonObject(); - assertTrue("expected getJSONObject to fail", false); - } catch (IllegalStateException e) { - assertEquals("Expected an exception message", - "Not a JSON Object: \"hello\"",e.getMessage()); - } - try { - jsonArray.get(4).getAsLong(); - assertTrue("expected getLong to fail", false); - } catch (NumberFormatException e) { - assertEquals("Expected an exception message", - "For input string: \"hello\"",e.getMessage()); - } - try { - jsonArray.get(10).getAsString(); - assertTrue("expected getString to fail", false); + jsonArray.getAsString(); + fail("expected getString to fail"); } catch (UnsupportedOperationException e) { assertEquals("Expected an exception message", - "JsonObject",e.getMessage()); + "JsonObject", e.getMessage()); + } + + jsonArray.remove(0); + jsonArray.add("hello"); + try { + jsonArray.getAsDouble(); + fail("expected getDouble to fail"); + } catch (NumberFormatException e) { + assertEquals("Expected an exception message", + "For input string: \"hello\"", e.getMessage()); + } + try { + jsonArray.getAsInt(); + fail("expected getInt to fail"); + } catch (NumberFormatException e) { + assertEquals("Expected an exception message", + "For input string: \"hello\"", e.getMessage()); + } + try { + jsonArray.get(0).getAsJsonArray(); + fail("expected getJSONArray to fail"); + } catch (IllegalStateException e) { + assertEquals("Expected an exception message", + "Not a JSON Array: \"hello\"", e.getMessage()); + } + try { + jsonArray.getAsJsonObject(); + fail("expected getJSONObject to fail"); + } catch (IllegalStateException e) { + assertEquals("Expected an exception message", + "Not a JSON Object: [\"hello\"]", e.getMessage()); + } + try { + jsonArray.getAsLong(); + fail("expected getLong to fail"); + } catch (NumberFormatException e) { + assertEquals("Expected an exception message", + "For input string: \"hello\"", e.getMessage()); } } } From 425cb25549ae83082b5e1ba4dfbc3bb635a15faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Mon, 2 Aug 2021 17:33:10 -0700 Subject: [PATCH 25/45] Adjust some minor details of #1391. Use two-space indentation for the new test. Use standard Google import style. Supply missing type argument for `TypeVariable`. --- .../com/google/gson/internal/$Gson$Types.java | 6 +- .../ReusedTypeVariablesFullyResolveTest.java | 57 ++++++++++--------- 2 files changed, 32 insertions(+), 31 deletions(-) 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 53985bc3..a708dc05 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 @@ -339,13 +339,13 @@ public final class $Gson$Types { } public static Type resolve(Type context, Class contextRawType, Type toResolve) { - return resolve(context, contextRawType, toResolve, new HashMap()); + return resolve(context, contextRawType, toResolve, new HashMap, Type>()); } private static Type resolve(Type context, Class contextRawType, Type toResolve, - Map visitedTypeVariables) { + Map, Type> visitedTypeVariables) { // this implementation is made a little more complicated in an attempt to avoid object-creation - TypeVariable resolving = null; + TypeVariable resolving = null; while (true) { if (toResolve instanceof TypeVariable) { TypeVariable typeVariable = (TypeVariable) toResolve; diff --git a/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java b/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java index e3ddd840..10c7c6db 100644 --- a/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java +++ b/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java @@ -1,16 +1,17 @@ package com.google.gson.functional; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.junit.Before; import org.junit.Test; - import java.util.Collection; import java.util.Iterator; import java.util.Set; -import static org.junit.Assert.*; - /** * This test covers the scenario described in #1390 where a type variable needs to be used * by a type definition multiple times. Both type variable references should resolve to the @@ -18,37 +19,37 @@ import static org.junit.Assert.*; */ public class ReusedTypeVariablesFullyResolveTest { - private Gson gson; + private Gson gson; - @Before - public void setUp() { - gson = new GsonBuilder().create(); - } + @Before + public void setUp() { + gson = new GsonBuilder().create(); + } - @SuppressWarnings("ConstantConditions") // The instances were being unmarshaled as Strings instead of TestEnums - @Test - public void testGenericsPreservation() { - TestEnumSetCollection withSet = gson.fromJson("{\"collection\":[\"ONE\",\"THREE\"]}", TestEnumSetCollection.class); - Iterator iterator = withSet.collection.iterator(); - assertNotNull(withSet); - assertNotNull(withSet.collection); - assertEquals(2, withSet.collection.size()); - TestEnum first = iterator.next(); - TestEnum second = iterator.next(); + @SuppressWarnings("ConstantConditions") // The instances were being unmarshaled as Strings instead of TestEnums + @Test + public void testGenericsPreservation() { + TestEnumSetCollection withSet = gson.fromJson("{\"collection\":[\"ONE\",\"THREE\"]}", TestEnumSetCollection.class); + Iterator iterator = withSet.collection.iterator(); + assertNotNull(withSet); + assertNotNull(withSet.collection); + assertEquals(2, withSet.collection.size()); + TestEnum first = iterator.next(); + TestEnum second = iterator.next(); - assertTrue(first instanceof TestEnum); - assertTrue(second instanceof TestEnum); - } + assertTrue(first instanceof TestEnum); + assertTrue(second instanceof TestEnum); + } - enum TestEnum { ONE, TWO, THREE } + enum TestEnum { ONE, TWO, THREE } - private static class TestEnumSetCollection extends SetCollection {} + private static class TestEnumSetCollection extends SetCollection {} - private static class SetCollection extends BaseCollection> {} + private static class SetCollection extends BaseCollection> {} - private static class BaseCollection> - { - public C collection; - } + private static class BaseCollection> + { + public C collection; + } } From 68f99f2440e93b1f80b241ea575929ffa79b9513 Mon Sep 17 00:00:00 2001 From: YOUNG CHA Date: Fri, 22 Mar 2019 17:11:11 +0900 Subject: [PATCH 26/45] Make EnumTypeAdapter friendly with obfuscation When enum value was obfuscated by proguard, EnumTypeAdapter raise NoSuchFieldException even if apply SerializedName annotation. Because EnumTypeAdapter cannot find obfuscated enum constant field with its name. --- .../google/gson/internal/bind/TypeAdapters.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java index 354ce5a1..f44e056a 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java +++ b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java @@ -17,6 +17,7 @@ package com.google.gson.internal.bind; import java.io.IOException; +import java.lang.reflect.Field; import java.math.BigDecimal; import java.math.BigInteger; import java.net.InetAddress; @@ -776,9 +777,14 @@ public final class TypeAdapters { public EnumTypeAdapter(Class classOfT) { try { - for (T constant : classOfT.getEnumConstants()) { + for (Field field : classOfT.getDeclaredFields()) { + if (!field.isEnumConstant()) { + continue; + } + field.setAccessible(true); + T constant = (T)(field.get(null)); String name = constant.name(); - SerializedName annotation = classOfT.getField(name).getAnnotation(SerializedName.class); + SerializedName annotation = field.getAnnotation(SerializedName.class); if (annotation != null) { name = annotation.value(); for (String alternate : annotation.alternate()) { @@ -788,7 +794,11 @@ public final class TypeAdapters { nameToConstant.put(name, constant); constantToName.put(constant, name); } - } catch (NoSuchFieldException e) { + } catch (IllegalAccessException e) { + throw new AssertionError(e); + } catch (NullPointerException e) { + throw new AssertionError(e); + } catch (ExceptionInInitializerError e) { throw new AssertionError(e); } } From 94f894cf44bb908c1dc9b5d7f0a10185a80dc7f8 Mon Sep 17 00:00:00 2001 From: YOUNG CHA Date: Mon, 25 Mar 2019 11:37:09 +0900 Subject: [PATCH 27/45] Add testcase for obfuscated enum class --- gson/pom.xml | 87 +++++++++++++++++++ .../functional/EnumWithObfuscatedTest.java | 60 +++++++++++++ gson/testcases-proguard.conf | 20 +++++ 3 files changed, 167 insertions(+) create mode 100644 gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java create mode 100644 gson/testcases-proguard.conf diff --git a/gson/pom.xml b/gson/pom.xml index 83f52b3a..bc5e8806 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -16,6 +16,12 @@ junit test + + com.github.wvengen + proguard-maven-plugin + 2.0.14 + test + @@ -69,6 +75,87 @@ + + com.coderplus.maven.plugins + copy-rename-maven-plugin + 1.0 + + + pre-obfuscate-class + process-test-classes + + rename + + + + + ${project.build.directory}/test-classes/com/google/gson/functional/EnumWithObfuscatedTest.class + ${project.build.directory}/test-classes-obfuscated-injar/com/google/gson/functional/EnumWithObfuscatedTest.class + + + ${project.build.directory}/test-classes/com/google/gson/functional/EnumWithObfuscatedTest$Gender.class + ${project.build.directory}/test-classes-obfuscated-injar/com/google/gson/functional/EnumWithObfuscatedTest$Gender.class + + + + + + + + com.github.wvengen + proguard-maven-plugin + + + process-test-classes + proguard + + + + 6.0.2 + true + test-classes-obfuscated-injar + test-classes-obfuscated-outjar + **/*.class + ${basedir}/testcases-proguard.conf + + ${project.build.directory}/classes + ${java.home}/jmods/java.base.jmod + + + + + net.sf.proguard + proguard-base + 6.0.2 + runtime + + + + + maven-resources-plugin + 2.7 + + + post-obfuscate-class + process-test-classes + + copy-resources + + + ${project.build.directory}/test-classes/com/google/gson/functional + + + ${project.build.directory}/test-classes-obfuscated-outjar/classes/classes/com/google/gson/functional + + EnumWithObfuscatedTest.class + EnumWithObfuscatedTest$Gender.class + + + + + + + diff --git a/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java b/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java new file mode 100644 index 00000000..a829b073 --- /dev/null +++ b/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gson.functional; + +import java.lang.reflect.Field; + +import com.google.gson.Gson; +import com.google.gson.annotations.SerializedName; + +import junit.framework.TestCase; + +/** + * Functional tests for enums with Proguard. + * + * @author Young Cha + */ +public class EnumWithObfuscatedTest extends TestCase { + private Gson gson; + + @Override + protected void setUp() throws Exception { + super.setUp(); + gson = new Gson(); + } + + public enum Gender { + @SerializedName("MAIL") + MALE, + + @SerializedName("FEMAIL") + FEMALE + } + + public void testEnumClassWithObfuscated() { + for (Gender enumConstant: Gender.class.getEnumConstants()) { + try { + Gender.class.getField(enumConstant.name()); + fail("Enum is not obfuscated"); + } catch (NoSuchFieldException ignore) { + } + } + + assertEquals(Gender.MALE, gson.fromJson("\"MAIL\"", Gender.class)); + assertEquals("\"MAIL\"", gson.toJson(Gender.MALE, Gender.class)); + } +} diff --git a/gson/testcases-proguard.conf b/gson/testcases-proguard.conf new file mode 100644 index 00000000..d42da0ab --- /dev/null +++ b/gson/testcases-proguard.conf @@ -0,0 +1,20 @@ +# Options from Android Gradle Plugins +# https://android.googlesource.com/platform/tools/base/+/refs/heads/studio-master-dev/build-system/gradle-core/src/main/resources/com/android/build/gradle +-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/* +-optimizationpasses 5 +-allowaccessmodification +-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep enum com.google.gson.functional.EnumWithObfuscatedTest$Gender +-keep class com.google.gson.functional.EnumWithObfuscatedTest { + public void test*(); + protected void setUp(); +} + +-dontwarn com.google.gson.functional.EnumWithObfuscatedTest +-dontwarn junit.framework.TestCase + From 7988fbfa9047f4373bd382efb1b5add660e28cfd Mon Sep 17 00:00:00 2001 From: YOUNG HO CHA Date: Thu, 10 Sep 2020 20:13:41 +0900 Subject: [PATCH 28/45] Update proguard plugin to support Java 11 compiler --- gson/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gson/pom.xml b/gson/pom.xml index bc5e8806..3ecd69a1 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -19,7 +19,7 @@ com.github.wvengen proguard-maven-plugin - 2.0.14 + 2.3.1 test @@ -111,7 +111,7 @@ - 6.0.2 + 6.2.2 true test-classes-obfuscated-injar test-classes-obfuscated-outjar @@ -126,7 +126,7 @@ net.sf.proguard proguard-base - 6.0.2 + 6.2.2 runtime From 1406477d0cd37e8d5d04e619ac349f0a6da614e3 Mon Sep 17 00:00:00 2001 From: YOUNG HO CHA Date: Thu, 10 Sep 2020 20:26:10 +0900 Subject: [PATCH 29/45] Fix post-obfuscate-class task to include obfuscated test classes --- gson/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gson/pom.xml b/gson/pom.xml index 3ecd69a1..baf919e3 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -145,7 +145,7 @@ ${project.build.directory}/test-classes/com/google/gson/functional - ${project.build.directory}/test-classes-obfuscated-outjar/classes/classes/com/google/gson/functional + ${project.build.directory}/test-classes-obfuscated-outjar/com/google/gson/functional EnumWithObfuscatedTest.class EnumWithObfuscatedTest$Gender.class From e99a4b1cb721d8153c4cf9659571fe7ea352799b Mon Sep 17 00:00:00 2001 From: YOUNG HO CHA Date: Sat, 12 Sep 2020 13:35:15 +0900 Subject: [PATCH 30/45] Move testcases-proguard.conf into gson/src/test/resources --- gson/pom.xml | 2 +- gson/{ => src/test/resources}/testcases-proguard.conf | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename gson/{ => src/test/resources}/testcases-proguard.conf (100%) diff --git a/gson/pom.xml b/gson/pom.xml index baf919e3..14089475 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -116,7 +116,7 @@ test-classes-obfuscated-injar test-classes-obfuscated-outjar **/*.class - ${basedir}/testcases-proguard.conf + ${basedir}/src/test/resources/testcases-proguard.conf ${project.build.directory}/classes ${java.home}/jmods/java.base.jmod diff --git a/gson/testcases-proguard.conf b/gson/src/test/resources/testcases-proguard.conf similarity index 100% rename from gson/testcases-proguard.conf rename to gson/src/test/resources/testcases-proguard.conf From 92a98dab02891af20913c07b4172614ca81b64b6 Mon Sep 17 00:00:00 2001 From: YOUNG HO CHA Date: Sat, 12 Sep 2020 13:36:14 +0900 Subject: [PATCH 31/45] Removed unused import --- .../java/com/google/gson/functional/EnumWithObfuscatedTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java b/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java index a829b073..8ad206a2 100644 --- a/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java +++ b/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java @@ -16,8 +16,6 @@ package com.google.gson.functional; -import java.lang.reflect.Field; - import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; From 6ac9f7d8400851fa3d0a136817e880126de9840b Mon Sep 17 00:00:00 2001 From: YOUNG HO CHA Date: Sat, 12 Sep 2020 13:40:09 +0900 Subject: [PATCH 32/45] Suppress unchecked type cast warning --- .../main/java/com/google/gson/internal/bind/TypeAdapters.java | 1 + 1 file changed, 1 insertion(+) diff --git a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java index f44e056a..f504ad3f 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java +++ b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java @@ -782,6 +782,7 @@ public final class TypeAdapters { continue; } field.setAccessible(true); + @SuppressWarnings("unchecked") T constant = (T)(field.get(null)); String name = constant.name(); SerializedName annotation = field.getAnnotation(SerializedName.class); From 20720d6a400eaea63c44f088479daea426e2de99 Mon Sep 17 00:00:00 2001 From: YOUNG HO CHA Date: Sat, 12 Sep 2020 13:57:35 +0900 Subject: [PATCH 33/45] Remove unnecessary catch block --- .../main/java/com/google/gson/internal/bind/TypeAdapters.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java index f504ad3f..e8052a70 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java +++ b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java @@ -797,10 +797,6 @@ public final class TypeAdapters { } } catch (IllegalAccessException e) { throw new AssertionError(e); - } catch (NullPointerException e) { - throw new AssertionError(e); - } catch (ExceptionInInitializerError e) { - throw new AssertionError(e); } } @Override public T read(JsonReader in) throws IOException { From 59a8aedb37ae35d4d2a4306c92efd463fffaaf69 Mon Sep 17 00:00:00 2001 From: YOUNG HO CHA Date: Wed, 4 Aug 2021 12:24:55 +0900 Subject: [PATCH 34/45] Use SecurityManager to read enum fields --- .../com/google/gson/internal/bind/TypeAdapters.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java index e8052a70..04b13ada 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java +++ b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java @@ -24,6 +24,8 @@ import java.net.InetAddress; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.sql.Timestamp; import java.util.ArrayList; import java.util.BitSet; @@ -777,11 +779,16 @@ public final class TypeAdapters { public EnumTypeAdapter(Class classOfT) { try { - for (Field field : classOfT.getDeclaredFields()) { + for (final Field field : classOfT.getDeclaredFields()) { if (!field.isEnumConstant()) { continue; } - field.setAccessible(true); + AccessController.doPrivileged(new PrivilegedAction() { + @Override public Void run() { + field.setAccessible(true); + return null; + } + }); @SuppressWarnings("unchecked") T constant = (T)(field.get(null)); String name = constant.name(); From d8c5fcf00bdd3170365e92e43880021031c7d005 Mon Sep 17 00:00:00 2001 From: YOUNG HO CHA Date: Wed, 4 Aug 2021 12:30:07 +0900 Subject: [PATCH 35/45] Fix indentation of EnumWithObfuscatedTest --- .../google/gson/functional/EnumWithObfuscatedTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java b/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java index 8ad206a2..080b81fa 100644 --- a/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java +++ b/gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java @@ -45,11 +45,11 @@ public class EnumWithObfuscatedTest extends TestCase { public void testEnumClassWithObfuscated() { for (Gender enumConstant: Gender.class.getEnumConstants()) { - try { - Gender.class.getField(enumConstant.name()); - fail("Enum is not obfuscated"); - } catch (NoSuchFieldException ignore) { - } + try { + Gender.class.getField(enumConstant.name()); + fail("Enum is not obfuscated"); + } catch (NoSuchFieldException ignore) { + } } assertEquals(Gender.MALE, gson.fromJson("\"MAIL\"", Gender.class)); From 178b221fa0dfc26bf27331e7ef6da9657bde1fdf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Aug 2021 03:02:56 +0000 Subject: [PATCH 36/45] Bump maven-resources-plugin from 2.7 to 3.2.0 Bumps [maven-resources-plugin](https://github.com/apache/maven-resources-plugin) from 2.7 to 3.2.0. - [Release notes](https://github.com/apache/maven-resources-plugin/releases) - [Commits](https://github.com/apache/maven-resources-plugin/compare/maven-resources-plugin-2.7...maven-resources-plugin-3.2.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-resources-plugin dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- gson/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gson/pom.xml b/gson/pom.xml index 14089475..10c7d2fe 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -133,7 +133,7 @@ maven-resources-plugin - 2.7 + 3.2.0 post-obfuscate-class From b7fce3850d6508ad18500abf3aac1354d277798d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Aug 2021 03:03:00 +0000 Subject: [PATCH 37/45] Bump proguard-maven-plugin from 2.3.1 to 2.4.0 Bumps [proguard-maven-plugin](https://github.com/wvengen/proguard-maven-plugin) from 2.3.1 to 2.4.0. - [Release notes](https://github.com/wvengen/proguard-maven-plugin/releases) - [Changelog](https://github.com/wvengen/proguard-maven-plugin/blob/master/CHANGELOG.md) - [Commits](https://github.com/wvengen/proguard-maven-plugin/commits) --- updated-dependencies: - dependency-name: com.github.wvengen:proguard-maven-plugin dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- gson/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gson/pom.xml b/gson/pom.xml index 14089475..65f063fe 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -19,7 +19,7 @@ com.github.wvengen proguard-maven-plugin - 2.3.1 + 2.4.0 test From da2bfd7d1c0462547cb470d992a861987f3cca16 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Aug 2021 03:03:02 +0000 Subject: [PATCH 38/45] Bump copy-rename-maven-plugin from 1.0 to 1.0.1 Bumps [copy-rename-maven-plugin](https://github.com/coderplus/copy-rename-maven-plugin) from 1.0 to 1.0.1. - [Release notes](https://github.com/coderplus/copy-rename-maven-plugin/releases) - [Commits](https://github.com/coderplus/copy-rename-maven-plugin/commits) --- updated-dependencies: - dependency-name: com.coderplus.maven.plugins:copy-rename-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- gson/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gson/pom.xml b/gson/pom.xml index 14089475..ddd01170 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -78,7 +78,7 @@ com.coderplus.maven.plugins copy-rename-maven-plugin - 1.0 + 1.0.1 pre-obfuscate-class From d3a75cb56937d687a66c8710e40c2da6223db0c3 Mon Sep 17 00:00:00 2001 From: Christoffer Quist Adamsen Date: Thu, 5 Aug 2021 09:18:32 +0200 Subject: [PATCH 39/45] Retain generic signature of TypeToken with R8 version 3.0 and higher --- examples/android-proguard-example/proguard.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/android-proguard-example/proguard.cfg b/examples/android-proguard-example/proguard.cfg index e0e0a97f..95f31ec6 100644 --- a/examples/android-proguard-example/proguard.cfg +++ b/examples/android-proguard-example/proguard.cfg @@ -25,4 +25,8 @@ @com.google.gson.annotations.SerializedName ; } +# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher. +-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken +-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken + ##---------------End: proguard configuration for Gson ---------- From 01ab13f701e6db84bdf37f602ef7af3c8d5c2f35 Mon Sep 17 00:00:00 2001 From: HiFromAjay Date: Thu, 5 Aug 2021 17:23:28 -0600 Subject: [PATCH 40/45] Remove unused imports [#1909, #1908] --- gson/src/test/java/com/google/gson/JsonArrayTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/gson/src/test/java/com/google/gson/JsonArrayTest.java b/gson/src/test/java/com/google/gson/JsonArrayTest.java index 86ef03c8..3975ce2c 100644 --- a/gson/src/test/java/com/google/gson/JsonArrayTest.java +++ b/gson/src/test/java/com/google/gson/JsonArrayTest.java @@ -16,12 +16,8 @@ package com.google.gson; -import junit.framework.TestCase; - import com.google.gson.common.MoreAsserts; - -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; +import junit.framework.TestCase; /** * @author Jesse Wilson From f98dabd1e966c97aa88ee74d587eb1ea810e39b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Aug 2021 03:04:02 +0000 Subject: [PATCH 41/45] Bump maven-scm-api from 1.11.2 to 1.11.3 Bumps [maven-scm-api](https://github.com/apache/maven-scm) from 1.11.2 to 1.11.3. - [Release notes](https://github.com/apache/maven-scm/releases) - [Commits](https://github.com/apache/maven-scm/compare/maven-scm-1.11.2...maven-scm-1.11.3) --- updated-dependencies: - dependency-name: org.apache.maven.scm:maven-scm-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2a445fd2..e75ff2a7 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ org.apache.maven.scm maven-scm-api - 1.11.2 + 1.11.3 org.apache.maven.scm From 205df01c047ecc03cf217f17e2030852a4ac96be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Aug 2021 03:04:06 +0000 Subject: [PATCH 42/45] Bump maven-scm-provider-gitexe from 1.11.2 to 1.11.3 Bumps maven-scm-provider-gitexe from 1.11.2 to 1.11.3. --- updated-dependencies: - dependency-name: org.apache.maven.scm:maven-scm-provider-gitexe dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2a445fd2..0860d72f 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.scm maven-scm-provider-gitexe - 1.11.2 + 1.11.3 From b41030d3dc965eca1b0a0f1c35ce185dd8e80e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Fri, 20 Aug 2021 09:07:19 -0700 Subject: [PATCH 43/45] [maven-release-plugin] prepare release gson-parent-2.8.8 --- gson/pom.xml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gson/pom.xml b/gson/pom.xml index 99ff049d..98d4a239 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -4,7 +4,7 @@ com.google.code.gson gson-parent - 2.8.8-SNAPSHOT + 2.8.8 gson diff --git a/pom.xml b/pom.xml index c6bb4276..cd3348d3 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.google.code.gson gson-parent - 2.8.8-SNAPSHOT + 2.8.8 pom Gson Parent @@ -31,7 +31,7 @@ https://github.com/google/gson/ scm:git:https://github.com/google/gson.git scm:git:git@github.com:google/gson.git - HEAD + gson-parent-2.8.8 From b2f661166f788185d5c3e5b588d0951c52ec2119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Fri, 20 Aug 2021 09:07:21 -0700 Subject: [PATCH 44/45] [maven-release-plugin] prepare for next development iteration --- gson/pom.xml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gson/pom.xml b/gson/pom.xml index 98d4a239..58d64989 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -4,7 +4,7 @@ com.google.code.gson gson-parent - 2.8.8 + 2.8.9-SNAPSHOT gson diff --git a/pom.xml b/pom.xml index cd3348d3..281f0f5c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.google.code.gson gson-parent - 2.8.8 + 2.8.9-SNAPSHOT pom Gson Parent @@ -31,7 +31,7 @@ https://github.com/google/gson/ scm:git:https://github.com/google/gson.git scm:git:git@github.com:google/gson.git - gson-parent-2.8.8 + HEAD From 03be83591467afc368608e80a03f9d6a0e9720fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Fri, 20 Aug 2021 10:02:13 -0700 Subject: [PATCH 45/45] Update change log, and version numbers in documentation. --- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- UserGuide.md | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98aa3ab0..4f58bb67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Change Log ========== +## Version 2.8.8 + +* Fixed issue with recursive types (#1390). +* Better behaviour with Java 9+ and `Unsafe` if there is a security manager (#1712). +* `EnumTypeAdapter` now works better when ProGuard has obfuscated enum fields (#1495). + ## Version 2.8.7 * Fixed `ISO8601UtilsTest` failing on systems with UTC+X. diff --git a/README.md b/README.md index 22ffdae5..7a003fbe 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ There are a few open-source projects that can convert Java objects to JSON. Howe Gradle: ```gradle dependencies { - implementation 'com.google.code.gson:gson:2.8.7' + implementation 'com.google.code.gson:gson:2.8.8' } ``` @@ -26,7 +26,7 @@ Maven: com.google.code.gson gson - 2.8.7 + 2.8.8 ``` diff --git a/UserGuide.md b/UserGuide.md index 22d4799d..5fae53c4 100644 --- a/UserGuide.md +++ b/UserGuide.md @@ -74,7 +74,7 @@ The Gson instance does not maintain any state while invoking Json operations. So ## Using Gson with Gradle/Android ``` dependencies { - implementation 'com.google.code.gson:gson:2.8.7' + implementation 'com.google.code.gson:gson:2.8.8' } ``` ## Using Gson with Maven @@ -86,7 +86,7 @@ To use Gson with Maven2/3, you can use the Gson version available in Maven Centr com.google.code.gson gson - 2.8.7 + 2.8.8 compile