Skip to content

Commit 7878ee2

Browse files
Don't rely on Android desugaring. (#2966)
Some Google libraries that rely on Gson require Android 23 *without* desugaring, because otherwise their clients would be forced to enable desugaring too. So revert to the standard animal-sniffer configuration, and reinstate the local `toIntExact` implementation.
1 parent c47db7b commit 7878ee2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.google.gson.internal.bind;
1818

19-
import static java.lang.Math.toIntExact;
20-
2119
import com.google.gson.Gson;
2220
import com.google.gson.JsonElement;
2321
import com.google.gson.JsonIOException;
@@ -773,6 +771,15 @@ long[] integerValues(Calendar calendar) {
773771
}
774772
};
775773

774+
// TODO: update this when we are on at least Android API Level 24.
775+
private static int toIntExact(long x) {
776+
int i = (int) x;
777+
if (i != x) {
778+
throw new IllegalArgumentException("Too big for an int: " + x);
779+
}
780+
return i;
781+
}
782+
776783
public static final TypeAdapterFactory CALENDAR_FACTORY =
777784
newFactoryForMultipleTypes(Calendar.class, GregorianCalendar.class, CALENDAR);
778785

@@ -833,7 +840,7 @@ public static TypeAdapterFactory javaTimeTypeAdapterFactory() {
833840
FactorySupplier supplier =
834841
(FactorySupplier) javaTimeTypeAdapterFactoryClass.getDeclaredConstructor().newInstance();
835842
return supplier.get();
836-
} catch (ReflectiveOperationException e) {
843+
} catch (ReflectiveOperationException | LinkageError e) {
837844
return null;
838845
}
839846
}

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,10 @@
522522
<configuration>
523523
<skip>${gson.isTestModule}</skip>
524524
<signature>
525-
<groupId>com.toasttab.android</groupId>
526-
<artifactId>gummy-bears-api-23</artifactId>
527-
<version>0.8.0</version>
525+
<!-- Google's internal use currently requires API Level 23 without desugaring. -->
526+
<groupId>net.sf.androidscents.signature</groupId>
527+
<artifactId>android-api-level-23</artifactId>
528+
<version>6.0_r3</version>
528529
</signature>
529530
<annotations>
530531
<annotation>com.google.gson.internal.bind.IgnoreJRERequirement</annotation>

0 commit comments

Comments
 (0)