Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static FirebaseFirestore getFirestoreForApp(String appName, String databaseId) {

setFirestoreSettings(instance, firestoreKey);

instanceCache.put(appName, new WeakReference<FirebaseFirestore>(instance));
instanceCache.put(firestoreKey, new WeakReference<FirebaseFirestore>(instance));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly fixes the key mismatch between lookup and storage, the underlying cache implementation remains problematic: (1) Key Reachability: WeakHashMap removes entries when the key object is no longer strongly reachable. Since firestoreKey is a local string created via concatenation, it will be garbage collected quickly, making the cache ineffective and leading to the repeated setFirestoreSettings calls this PR aims to avoid. (2) Thread Safety: WeakHashMap is not thread-safe. Concurrent access to this static map from multiple threads can cause race conditions or internal corruption. (3) WeakReference Handling: The retrieval logic at line 43 (visible in context) returns cachedInstance.get() without checking for null. If the WeakReference is cleared, the method returns null, which may cause a NullPointerException in the caller. Consider replacing instanceCache with a ConcurrentHashMap to ensure persistence, thread safety, and reliability.


return instance;
}
Expand Down
Loading