Skip to content

Commit 93cdb04

Browse files
authored
Fixing NPE and correcting corresponding annotations. (#1714)
Reported by Google Duo dog-fooding : b/158637349
1 parent 5ea6635 commit 93cdb04

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ private PersistedInstallationEntry registerFidWithServer(PersistedInstallationEn
465465
// Note: Default value of instanceIdMigrationAuth: null
466466
String iidToken = null;
467467

468-
if (prefs.getFirebaseInstallationId().length() == 11) {
468+
if (prefs.getFirebaseInstallationId() != null
469+
&& prefs.getFirebaseInstallationId().length() == 11) {
469470
// For a default firebase installation, read the stored star scoped iid token. This token
470471
// will be used for authenticating Instance-ID when migrating to FIS.
471472
iidToken = iidStore.readToken();

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public FirebaseInstallationServiceClient(
134134
@NonNull
135135
public InstallationResponse createFirebaseInstallation(
136136
@NonNull String apiKey,
137-
@NonNull String fid,
137+
@Nullable String fid,
138138
@NonNull String projectID,
139139
@NonNull String appId,
140140
@Nullable String iidToken)
@@ -186,7 +186,7 @@ public InstallationResponse createFirebaseInstallation(
186186
}
187187

188188
private void writeFIDCreateRequestBodyToOutputStream(
189-
HttpURLConnection httpURLConnection, @NonNull String fid, @NonNull String appId)
189+
HttpURLConnection httpURLConnection, @Nullable String fid, @NonNull String appId)
190190
throws IOException {
191191
writeRequestBodyToOutputStream(
192192
httpURLConnection, getJsonBytes(buildCreateFirebaseInstallationRequestBody(fid, appId)));
@@ -231,7 +231,8 @@ private static void writeRequestBodyToOutputStream(URLConnection urlConnection,
231231
* @throws IllegalStateException If {@link JSONException} is thrown due to non-null names while
232232
* {@link JSONObject} creation.
233233
*/
234-
private static JSONObject buildCreateFirebaseInstallationRequestBody(String fid, String appId) {
234+
private static JSONObject buildCreateFirebaseInstallationRequestBody(
235+
@Nullable String fid, @NonNull String appId) {
235236
try {
236237
JSONObject firebaseInstallationData = new JSONObject();
237238
firebaseInstallationData.put("fid", fid);

0 commit comments

Comments
 (0)