Skip to content

fix(remoteconfig): keep data and source when copying a config value - #16825

Merged
ncooke3 merged 4 commits into
mainfrom
pb-rc-config-value-copy
Oct 27, 2026
Merged

ncooke3 merged 4 commits into
mainfrom
pb-rc-config-value-copy

Conversation

@paulb777

@paulb777 paulb777 commented Oct 2, 2026

Copy link
Copy Markdown
Member

Problem

FIRRemoteConfigValue (RemoteConfigValue in Swift) publicly conforms to NSCopying, but
-copyWithZone: sent initWithData: to the new instance. The class only implements
initWithData:source:, so [value copy] raised an exception instead of returning a copy:

NSInvalidArgumentException: -[FIRRemoteConfigValue initWithData:]: unrecognized selector sent to instance

The bug has been there since Remote Config was open-sourced. The SDK never copies values itself,
so only app code that copies a value hits it (copy, a copy property, or other NSCopying
APIs).

Change

  • -copyWithZone: now uses the designated initializer, initWithData:_data source:_source. The
    copy keeps both the backing data and the value source.
  • Added testCopyPreservesDataAndSource to RCNConfigValueTest.m. It uses a Default source so
    the test also catches a copy that drops the source (it would read back as Remote = 0).
  • CHANGELOG entry.

Testing

xcodebuild -scheme RemoteConfigUnit test -destination 'platform=macOS' \
  -only-testing:RemoteConfigUnit/FIRRemoteConfigValueTest
  • Without the fix, testCopyPreservesDataAndSource fails: XCTAssertNoThrow catches the
    unrecognized-selector NSInvalidArgumentException.
  • With the fix, it passes.
  • xcodebuild -scheme RemoteConfigUnit test -destination 'platform=macOS': 130 tests, 0 failures.

Fixes #16804

`FIRRemoteConfigValue` publicly conforms to `NSCopying`, but
`-copyWithZone:` sent `initWithData:` to the new instance. The class only
implements `initWithData:source:`, so copying any value raised an
unrecognized-selector exception instead of returning a copy.

Copy with the designated initializer instead, so the copy keeps both the
backing data and the value source.

Fixes #16804
@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@paulb777

paulb777 commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request fixes a crash and data loss issue when copying a FIRRemoteConfigValue by ensuring that the copy operation preserves both the value's data and its source. A unit test was added to verify this behavior. The review feedback suggests renaming the local variable copy in the new unit test to copiedValue to avoid potential confusion or shadowing with the Objective-C copy selector.

Comment thread FirebaseRemoteConfig/Tests/Unit/RCNConfigValueTest.m Outdated
Use copiedValue instead of copy for the local, so that it doesn't read like the copy selector, as suggested in review.
@ncooke3
ncooke3 merged commit a36958c into main Oct 27, 2026
48 checks passed
@ncooke3
ncooke3 deleted the pb-rc-config-value-copy branch October 27, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copying FIRRemoteConfigValue sends an unsupported initializer selector

3 participants