Skip to content

Commit 1162c4a

Browse files
authored
Handling AssertionError thrown by JsonReader causing Play Games app-crashes. (#1916)
* Handling AssertionError thrown by JsonReader causing Play Games app crashes. * Addressing rayo's comments
1 parent 296aa4f commit 1162c4a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

firebase-installations/src/main/java/com/google/firebase/installations/remote/FirebaseInstallationServiceClient.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public InstallationResponse createFirebaseInstallation(
173173

174174
// Return empty installation response with BAD_CONFIG response code after max retries
175175
return InstallationResponse.builder().setResponseCode(ResponseCode.BAD_CONFIG).build();
176-
} catch (IOException ignored) {
176+
} catch (AssertionError | IOException ignored) {
177177
retryCount++;
178178
} finally {
179179
httpURLConnection.disconnect();
@@ -394,7 +394,8 @@ public TokenResult generateAuthToken(
394394
logBadConfigError();
395395

396396
return TokenResult.builder().setResponseCode(TokenResult.ResponseCode.BAD_CONFIG).build();
397-
} catch (IOException ignored) {
397+
// TODO(b/166168291): Remove code duplication and clean up this class.
398+
} catch (AssertionError | IOException ignored) {
398399
retryCount++;
399400
} finally {
400401
httpURLConnection.disconnect();
@@ -446,11 +447,14 @@ private HttpURLConnection openHttpURLConnection(URL url, String apiKey)
446447
}
447448

448449
// Read the response from the createFirebaseInstallation API.
449-
private InstallationResponse readCreateResponse(HttpURLConnection conn) throws IOException {
450+
private InstallationResponse readCreateResponse(HttpURLConnection conn)
451+
throws AssertionError, IOException {
450452
InputStream inputStream = conn.getInputStream();
451453
JsonReader reader = new JsonReader(new InputStreamReader(inputStream, UTF_8));
452454
TokenResult.Builder tokenResult = TokenResult.builder();
453455
InstallationResponse.Builder builder = InstallationResponse.builder();
456+
// JsonReader.peek will sometimes throw AssertionErrors in Android 8.0 and above. See
457+
// https://b.corp.google.com/issues/79920590 for details.
454458
reader.beginObject();
455459
while (reader.hasNext()) {
456460
String name = reader.nextName();
@@ -486,10 +490,13 @@ private InstallationResponse readCreateResponse(HttpURLConnection conn) throws I
486490
}
487491

488492
// Read the response from the generateAuthToken FirebaseInstallation API.
489-
private TokenResult readGenerateAuthTokenResponse(HttpURLConnection conn) throws IOException {
493+
private TokenResult readGenerateAuthTokenResponse(HttpURLConnection conn)
494+
throws AssertionError, IOException {
490495
InputStream inputStream = conn.getInputStream();
491496
JsonReader reader = new JsonReader(new InputStreamReader(inputStream, UTF_8));
492497
TokenResult.Builder builder = TokenResult.builder();
498+
// JsonReader.peek will sometimes throw AssertionErrors in Android 8.0 and above. See
499+
// https://b.corp.google.com/issues/79920590 for details.
493500
reader.beginObject();
494501
while (reader.hasNext()) {
495502
String name = reader.nextName();

0 commit comments

Comments
 (0)