Skip to content

Give android.os.Bundle the Android class's semantics and the members Firebase uses - #81

Merged
nbransby merged 2 commits into
masterfrom
bundle-api
Oct 31, 2026
Merged

nbransby merged 2 commits into
masterfrom
bundle-api

Conversation

@nbransby

@nbransby nbransby commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

The android.os.Bundle shim held a map behind four getters whose behaviour differed from Android's: containsKey threw an IllegalArgumentException for a missing key (and get/getString with it), and a getter threw a ClassCastException for a value of another type. It now mirrors android.os.Bundle for the primitive, String and Bundle values the ported libraries and firebase-kotlin-sdk's Analytics use.

  • A no-argument constructor; the Map constructor stays for ServiceInfo's metadata, and the copy constructor copies.
  • putBoolean, putInt, putLong, putFloat, putDouble, putString, putBundle, putAll, remove, clear, size, isEmpty, keySet, containsKey, get.
  • The matching getters with and without a default: a getter returns its default when the key is missing or the value has another type, as on Android, and getString(key, default) returns the default for a null value too.

The motivation is firebase-kotlin-sdk's com.google.firebase compatibility layer (GitLiveApp/firebase-kotlin-sdk#891): Analytics events are built from a Bundle, and the layer's header stub for the class is verified against this port on the JVM, where 20 of the members it declares were tolerated as missing. With this release that exclusion list can go.

BundleTest covers the typed round trip, the defaults for a missing key or another type, and copy, merge, remove and clear. FirebaseAppTest, FirebasePlatformTest and FirebaseRemoteConfigTest, which read component metadata through the class, still pass.

…Firebase uses

The shim held a map behind four getters whose behaviour differed from Android's: containsKey threw for a missing key, and a getter threw a ClassCastException for a value of another type. It now mirrors android.os.Bundle for the primitive, String and Bundle values the ported libraries and firebase-kotlin-sdk's Analytics use: a no-argument constructor, the put methods for boolean, int, long, float, double, String and Bundle, the matching getters with and without a default, get, containsKey answering rather than throwing, putAll, remove, clear, size and isEmpty, with a getter returning its default when the key is missing or the value has another type, as on Android. The Map constructor stays for ServiceInfo's metadata.
Copilot AI balanced review requested due to automatic review settings October 31, 2026 04:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new mutators can throw UnsupportedOperationException because Bundle(Map) retains potentially immutable input maps instead of copying them into a mutable backing map.

1 open issue
What changed in this PR

This PR expands the android.os.Bundle shim to support Firebase Analytics and align its typed getters with Android’s default-value behavior.

Changes:

  • Adds a no-argument constructor, typed setters, and collection operations.
  • Returns defaults for missing or mismatched values instead of throwing.
  • Adds tests for typed values, defaults, copying, and mutation.
File Description
src/​test/​kotlin/​BundleTest.kt Tests typed values, fallback behavior, and collection operations.
src/​main/​java/​android/​os/​Bundle.java Expands the Bundle API and implements Android-compatible getter behavior.

Review effort: Balanced

Comment thread src/main/java/android/os/Bundle.java Resolved
@nbransby
nbransby merged commit 00b2df6 into master Oct 31, 2026
1 check passed
@nbransby
nbransby deleted the bundle-api branch October 31, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants