Skip to content

RemoteMessage.getData() should return a defensive copy of the intneral ArrayMap from its public API #7255

@dlam

Description

@dlam

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:

public static ArrayMap<String, String> extractDeveloperDefinedPayload(Bundle bundle) {

and the affected api in the linked buganizer issue against androidx.collection:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions