From 9335436cc5871214a1c95dbc5941b85a9d4967a1 Mon Sep 17 00:00:00 2001 From: Guillaume Bernos Date: Thu, 31 Oct 2024 11:33:50 +0100 Subject: [PATCH] chore(firestore): clean up the code for checking if instance exists (#13576) --- .../FlutterFirebaseFirestoreMessageCodec.java | 10 +++++----- .../firestore/FlutterFirebaseFirestorePlugin.java | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestoreMessageCodec.java b/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestoreMessageCodec.java index c7ceb6b36f7c..0e0247915b7c 100644 --- a/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestoreMessageCodec.java +++ b/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestoreMessageCodec.java @@ -290,11 +290,11 @@ private FirebaseFirestore readFirestoreInstance(ByteBuffer buffer) { String databaseURL = (String) readValue(buffer); FirebaseFirestoreSettings settings = (FirebaseFirestoreSettings) readValue(buffer); synchronized (FlutterFirebaseFirestorePlugin.firestoreInstanceCache) { - if (FlutterFirebaseFirestorePlugin.getFirestoreInstanceByNameAndDatabaseUrl( - appName, databaseURL) - != null) { - return FlutterFirebaseFirestorePlugin.getFirestoreInstanceByNameAndDatabaseUrl( - appName, databaseURL); + FirebaseFirestore cachedFirestoreInstance = + FlutterFirebaseFirestorePlugin.getFirestoreInstanceByNameAndDatabaseUrl( + appName, databaseURL); + if (cachedFirestoreInstance != null) { + return cachedFirestoreInstance; } FirebaseApp app = FirebaseApp.getInstance(appName); diff --git a/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java b/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java index 0804d9939438..35e4697f7128 100644 --- a/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java +++ b/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java @@ -309,11 +309,11 @@ static FirebaseFirestoreSettings getSettingsFromPigeon( public static FirebaseFirestore getFirestoreFromPigeon( GeneratedAndroidFirebaseFirestore.FirestorePigeonFirebaseApp pigeonApp) { synchronized (FlutterFirebaseFirestorePlugin.firestoreInstanceCache) { - if (FlutterFirebaseFirestorePlugin.getFirestoreInstanceByNameAndDatabaseUrl( - pigeonApp.getAppName(), pigeonApp.getDatabaseURL()) - != null) { - return FlutterFirebaseFirestorePlugin.getFirestoreInstanceByNameAndDatabaseUrl( - pigeonApp.getAppName(), pigeonApp.getDatabaseURL()); + FirebaseFirestore cachedFirestoreInstance = + FlutterFirebaseFirestorePlugin.getFirestoreInstanceByNameAndDatabaseUrl( + pigeonApp.getAppName(), pigeonApp.getDatabaseURL()); + if (cachedFirestoreInstance != null) { + return cachedFirestoreInstance; } FirebaseApp app = FirebaseApp.getInstance(pigeonApp.getAppName());