Skip to content

Commit 550de9b

Browse files
Merge branch 'main' into gson_default
2 parents 0d41f76 + 286843d commit 550de9b

File tree

21 files changed

+900
-124
lines changed

21 files changed

+900
-124
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ jobs:
3838
runs-on: ubuntu-latest
3939

4040
steps:
41-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
41+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
4242
- name: "Set up JDK ${{ matrix.java }}"
43-
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
43+
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
4444
with:
4545
distribution: 'temurin'
4646
java-version: ${{ matrix.java }}
@@ -54,9 +54,9 @@ jobs:
5454
name: Build Gson subset
5555
runs-on: ubuntu-latest
5656
steps:
57-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
57+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
5858
- name: Set up JDK
59-
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
59+
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
6060
with:
6161
distribution: 'temurin'
6262
java-version: 21
@@ -77,9 +77,9 @@ jobs:
7777
runs-on: ubuntu-latest
7878

7979
steps:
80-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
80+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
8181
- name: "Set up GraalVM"
82-
uses: graalvm/setup-graalvm@eec48106e0bf45f2976c2ff0c3e22395cced8243 # v1.4.2
82+
uses: graalvm/setup-graalvm@790e28947b79a9c09c3391c0f18bf8d0f102ed69 # v1.4.4
8383
with:
8484
java-version: ${{ matrix.java }}
8585
distribution: 'graalvm'
@@ -96,9 +96,9 @@ jobs:
9696
runs-on: ubuntu-latest
9797

9898
steps:
99-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
99+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
100100
- name: Set up JDK
101-
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
101+
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
102102
with:
103103
distribution: 'temurin'
104104
java-version: 17

.github/workflows/check-android-compatibility.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
steps:
27-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
27+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2828

2929
- name: Set up JDK
30-
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
30+
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
3131
with:
3232
distribution: 'temurin'
3333
java-version: '17'

.github/workflows/check-api-compatibility.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ jobs:
2525

2626
steps:
2727
- name: Check out old version
28-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
28+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2929
with:
3030
ref: ${{ github.event.pull_request.base.sha }}
3131
path: 'gson-old-japicmp'
3232

3333
- name: Set up JDK
34-
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
34+
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
3535
with:
3636
distribution: 'temurin'
3737
java-version: '17'
@@ -46,15 +46,15 @@ jobs:
4646
mvn install -Dmaven.test.skip --projects '!metrics,!test-graal-native-image,!test-jpms,!test-shrinker'
4747
4848
- name: Check out new version
49-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
49+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
5050

5151
- name: Check API compatibility
5252
id: check-compatibility
5353
run: |
5454
mvn package japicmp:cmp --fail-at-end -Dmaven.test.skip --projects '!metrics,!test-graal-native-image,!test-jpms,!test-shrinker'
5555
5656
- name: Upload API differences artifacts
57-
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
57+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
5858
# Run on workflow success (in that case differences report might include added methods and classes)
5959
# or when API compatibility check failed
6060
if: success() || ( failure() && steps.check-compatibility.outcome == 'failure' )

.github/workflows/cifuzz.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ jobs:
2525
dry-run: false
2626
output-sarif: true
2727
- name: Upload Crash
28-
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
28+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
2929
if: failure() && steps.build.outcome == 'success'
3030
with:
3131
name: artifacts
3232
path: ./out/artifacts
3333
- name: Upload Sarif
3434
if: always() && steps.build.outcome == 'success'
35-
uses: github/codeql-action/upload-sarif@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
35+
uses: github/codeql-action/upload-sarif@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
3636
with:
3737
# Path to SARIF file relative to the root of the repository
3838
sarif_file: cifuzz-sarif/results.sarif

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ jobs:
3737

3838
steps:
3939
- name: Checkout repository
40-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
40+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
4141

4242
- name: Set up JDK
4343
if: ${{ matrix.language == 'java' }}
44-
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
44+
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
4545
with:
4646
distribution: 'temurin'
4747
java-version: '17'
4848
cache: 'maven'
4949

5050
# Initializes the CodeQL tools for scanning
5151
- name: Initialize CodeQL
52-
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
52+
uses: github/codeql-action/init@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
5353
with:
5454
languages: ${{ matrix.language }}
5555
build-mode: ${{ matrix.build-mode }}
@@ -65,6 +65,6 @@ jobs:
6565
mvn compile
6666
6767
- name: Perform CodeQL Analysis
68-
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
68+
uses: github/codeql-action/analyze@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
6969
with:
7070
category: "/language:${{ matrix.language }}"

.github/workflows/scorecard.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
steps:
3636
- name: "Checkout code"
37-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
37+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
3838
with:
3939
persist-credentials: false
4040

@@ -64,7 +64,7 @@ jobs:
6464
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
6565
# format to the repository Actions tab.
6666
- name: "Upload artifact"
67-
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
67+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
6868
with:
6969
name: SARIF file
7070
path: results.sarif
@@ -73,6 +73,6 @@ jobs:
7373
# Upload the results to GitHub's code scanning dashboard (optional).
7474
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
7575
- name: "Upload to code-scanning"
76-
uses: github/codeql-action/upload-sarif@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
76+
uses: github/codeql-action/upload-sarif@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
7777
with:
7878
sarif_file: results.sarif

gson/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<dependency>
5151
<groupId>com.google.errorprone</groupId>
5252
<artifactId>error_prone_annotations</artifactId>
53-
<version>2.43.0</version>
53+
<version>2.45.0</version>
5454
</dependency>
5555

5656
<dependency>
@@ -211,7 +211,7 @@
211211
<dependency>
212212
<groupId>com.guardsquare</groupId>
213213
<artifactId>proguard-base</artifactId>
214-
<version>7.8.0</version>
214+
<version>7.8.2</version>
215215
</dependency>
216216
<dependency>
217217
<groupId>com.guardsquare</groupId>
@@ -235,7 +235,7 @@
235235
<plugin>
236236
<groupId>org.apache.maven.plugins</groupId>
237237
<artifactId>maven-resources-plugin</artifactId>
238-
<version>3.3.1</version>
238+
<version>3.4.0</version>
239239
<executions>
240240
<execution>
241241
<id>pre-obfuscate-class</id>

gson/src/main/java/com/google/gson/Gson.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.google.gson;
1818

1919
import static com.google.gson.GsonBuilder.newImmutableList;
20+
import static com.google.gson.internal.bind.TypeAdapters.atomicLongAdapter;
21+
import static com.google.gson.internal.bind.TypeAdapters.atomicLongArrayAdapter;
2022

2123
import com.google.gson.annotations.JsonAdapter;
2224
import com.google.gson.internal.ConstructorConstructor;
@@ -39,6 +41,9 @@
3941
import java.io.StringReader;
4042
import java.io.Writer;
4143
import java.lang.reflect.Type;
44+
import java.text.DateFormat;
45+
import java.util.ArrayList;
46+
import java.util.Collections;
4247
import java.util.HashMap;
4348
import java.util.List;
4449
import java.util.Map;
@@ -305,6 +310,14 @@ public boolean htmlSafe() {
305310
return htmlSafe;
306311
}
307312

313+
private TypeAdapter<Number> floatAdapter() {
314+
return serializeSpecialFloatingPointValues ? TypeAdapters.FLOAT : TypeAdapters.FLOAT_STRICT;
315+
}
316+
317+
private TypeAdapter<Number> doubleAdapter() {
318+
return serializeSpecialFloatingPointValues ? TypeAdapters.DOUBLE : TypeAdapters.DOUBLE_STRICT;
319+
}
320+
308321
/**
309322
* Returns the type adapter for {@code type}.
310323
*

gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public T construct() {
449449
// New exception is created every time to avoid keeping a reference to an exception with
450450
// potentially long stack trace, causing a memory leak
451451
// (which would happen if the exception was already created when the
452-
// `ExceptionObjectConstructor` is created)
452+
// `ThrowingObjectConstructor` is created)
453453
throw new JsonIOException(exceptionMessage);
454454
}
455455
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,16 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
5050
}
5151
};
5252

53-
private final Map<String, T> nameToConstant = new HashMap<>();
54-
private final Map<String, T> stringToConstant = new HashMap<>();
55-
private final Map<T, String> constantToName = new HashMap<>();
53+
/**
54+
* Taken from Java 19 method {@link HashMap.newHashMap}, using default load factor {@code 0.75F}.
55+
*/
56+
private static int calculateHashMapCapacity(int numMappings) {
57+
return (int) Math.ceil(numMappings / 0.75F);
58+
}
59+
60+
private final Map<String, T> nameToConstant;
61+
private final Map<String, T> stringToConstant;
62+
private final Map<T, String> constantToName;
5663

5764
private EnumTypeAdapter(Class<T> classOfT) {
5865
try {
@@ -71,6 +78,12 @@ private EnumTypeAdapter(Class<T> classOfT) {
7178
// one declared field which is not an enum constant, namely the implicit $VALUES array
7279
fields = Arrays.copyOf(fields, constantCount);
7380

81+
int hashMapCapacity = calculateHashMapCapacity(constantCount);
82+
nameToConstant = new HashMap<>(hashMapCapacity);
83+
stringToConstant = new HashMap<>(hashMapCapacity);
84+
// Don't use `EnumMap` here; that can break when using ProGuard or R8
85+
constantToName = new HashMap<>(hashMapCapacity);
86+
7487
AccessibleObject.setAccessible(fields, true);
7588

7689
for (Field constantField : fields) {

0 commit comments

Comments
 (0)