From a631f9a43364a0e38b1fc352b6cb108b06db4214 Mon Sep 17 00:00:00 2001 From: Tom Andersen Date: Mon, 7 Nov 2022 12:09:19 -0500 Subject: [PATCH] Fix MultiDB Regression --- .../com/google/firebase/cloud/FirestoreClient.java | 3 ++- .../google/firebase/cloud/FirestoreClientTest.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/firebase/cloud/FirestoreClient.java b/src/main/java/com/google/firebase/cloud/FirestoreClient.java index 101201781..e1672ec34 100644 --- a/src/main/java/com/google/firebase/cloud/FirestoreClient.java +++ b/src/main/java/com/google/firebase/cloud/FirestoreClient.java @@ -79,7 +79,8 @@ public static Firestore getFirestore() { */ @NonNull public static Firestore getFirestore(FirebaseApp app) { - return getFirestore(app, ImplFirebaseTrampolines.getFirestoreOptions(app).getDatabaseId()); + final FirestoreOptions firestoreOptions = ImplFirebaseTrampolines.getFirestoreOptions(app); + return getFirestore(app, firestoreOptions == null ? null : firestoreOptions.getDatabaseId()); } /** diff --git a/src/test/java/com/google/firebase/cloud/FirestoreClientTest.java b/src/test/java/com/google/firebase/cloud/FirestoreClientTest.java index a5f617ce6..31ea33618 100644 --- a/src/test/java/com/google/firebase/cloud/FirestoreClientTest.java +++ b/src/test/java/com/google/firebase/cloud/FirestoreClientTest.java @@ -79,6 +79,20 @@ public void testServiceAccountProjectId() throws IOException { assertNotSame(firestore1, firestore2); } + @Test + public void testAbsentFirestoreOptions() throws Exception { + String projectId = "test-proj"; + FirebaseOptions options = FirebaseOptions.builder() + .setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream())) + .setProjectId(projectId) + .build(); + + FirebaseApp.initializeApp(options); + Firestore firestore = FirestoreClient.getFirestore(); + assertEquals(projectId, firestore.getOptions().getProjectId()); + assertEquals("(default)", firestore.getOptions().getDatabaseId()); + } + @Test public void testFirestoreOptions() throws IOException { final String databaseId = "databaseIdInTestFirestoreOptions";