Repository navigation
Give android.os.Bundle the Android class's semantics and the members Firebase uses - #81
Merged
Merged
Conversation
…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.
There was a problem hiding this comment.
🟡 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
This was referenced Oct 31, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The
android.os.Bundleshim held a map behind four getters whose behaviour differed from Android's:containsKeythrew anIllegalArgumentExceptionfor a missing key (andget/getStringwith it), and a getter threw aClassCastExceptionfor a value of another type. It now mirrorsandroid.os.Bundlefor the primitive,StringandBundlevalues the ported libraries and firebase-kotlin-sdk's Analytics use.Mapconstructor stays forServiceInfo's metadata, and the copy constructor copies.putBoolean,putInt,putLong,putFloat,putDouble,putString,putBundle,putAll,remove,clear,size,isEmpty,keySet,containsKey,get.getString(key, default)returns the default for a null value too.The motivation is firebase-kotlin-sdk's
com.google.firebasecompatibility layer (GitLiveApp/firebase-kotlin-sdk#891): Analytics events are built from aBundle, 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.BundleTestcovers the typed round trip, the defaults for a missing key or another type, and copy, merge, remove and clear.FirebaseAppTest,FirebasePlatformTestandFirebaseRemoteConfigTest, which read component metadata through the class, still pass.