diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java index ee2201fb7f3..da460dae2d0 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -465,7 +465,8 @@ private PersistedInstallationEntry registerFidWithServer(PersistedInstallationEn // Note: Default value of instanceIdMigrationAuth: null String iidToken = null; - if (prefs.getFirebaseInstallationId().length() == 11) { + if (prefs.getFirebaseInstallationId() != null + && prefs.getFirebaseInstallationId().length() == 11) { // For a default firebase installation, read the stored star scoped iid token. This token // will be used for authenticating Instance-ID when migrating to FIS. iidToken = iidStore.readToken(); diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/remote/FirebaseInstallationServiceClient.java b/firebase-installations/src/main/java/com/google/firebase/installations/remote/FirebaseInstallationServiceClient.java index 2775cf564f8..8de1cbcf1ef 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/remote/FirebaseInstallationServiceClient.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/remote/FirebaseInstallationServiceClient.java @@ -134,7 +134,7 @@ public FirebaseInstallationServiceClient( @NonNull public InstallationResponse createFirebaseInstallation( @NonNull String apiKey, - @NonNull String fid, + @Nullable String fid, @NonNull String projectID, @NonNull String appId, @Nullable String iidToken) @@ -186,7 +186,7 @@ public InstallationResponse createFirebaseInstallation( } private void writeFIDCreateRequestBodyToOutputStream( - HttpURLConnection httpURLConnection, @NonNull String fid, @NonNull String appId) + HttpURLConnection httpURLConnection, @Nullable String fid, @NonNull String appId) throws IOException { writeRequestBodyToOutputStream( httpURLConnection, getJsonBytes(buildCreateFirebaseInstallationRequestBody(fid, appId))); @@ -231,7 +231,8 @@ private static void writeRequestBodyToOutputStream(URLConnection urlConnection, * @throws IllegalStateException If {@link JSONException} is thrown due to non-null names while * {@link JSONObject} creation. */ - private static JSONObject buildCreateFirebaseInstallationRequestBody(String fid, String appId) { + private static JSONObject buildCreateFirebaseInstallationRequestBody( + @Nullable String fid, @NonNull String appId) { try { JSONObject firebaseInstallationData = new JSONObject(); firebaseInstallationData.put("fid", fid);