RemoteMessage.getData() should return a defensive copy of the intneral ArrayMap from its public API
Context: https://issuetracker.google.com/393513316
ArrayMap is a performance-sensitive collection which does not support holding references to the returned Map.Entry when iterating through it. Many kotlin-stdlib extensions on collections do not create defensive copies (intentionally for performance), so it is quite confusing to end users that for example RemoteMessage.data.entries.sortedBy { ..} returned a list of the last entry repeated size times.
Instead, I would generally recommend that public API return defensive copies of collections to avoid this confusion and to keep the performance sensitive stuff internal. We have a similar rule for android platform + libraries here: go/android-api-guidelines#type-semantics
I believe this is the problematic call-site: https://github.com/firebase/firebase-android-sdk/blob/5e778b940e72d6ce10455a6604f2857820df1d28/firebase-messaging/src/main/java/com/google/firebase/messaging/Constants.java#L120
and the affected api in the linked buganizer issue against androidx.collection: https://github.com/firebase/firebase-android-sdk/blob/5e778b940e72d6ce10455a6604f2857820df1d28/firebase-messaging/src/main/java/com/google/firebase/messaging/RemoteMessage.java#L130
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Hi @dlam, thank you for raising the issue. Let me raise this to our engineers and get back to you! Thanks!
PR #7513