Skip to content

feat: Allow for providers with equal name in the multiprovider - #1848

Open
chrfwow wants to merge 2 commits into
open-feature:mainfrom
chrfwow:allow-non-unique-provider-names
Open

feat: Allow for providers with equal name in the multiprovider#1848
chrfwow wants to merge 2 commits into
open-feature:mainfrom
chrfwow:allow-non-unique-provider-names

Conversation

@chrfwow

@chrfwow chrfwow commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

This PR

Adds support for different providers with the same name in the multi provider. Since the interface Strategy has changed, this would be a breaking change if the multiprovider was not experimental.

The downside is, that the providers are not passed to the Strategy in a map, which makes the retrieval of a provider per name more difficult, and, depending on the number of providers, slower. However, since there will only ever be a handfull of providers, this should make no difference in real scenarios. Furthermore, the current map based version may result in unexpected behavior when two or more providers have the same name.

Related Issues

Fixes #1792

@chrfwow
chrfwow requested review from a team as code owners February 10, 2026 14:58
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @chrfwow, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the MultiProvider component to allow for the registration and management of multiple feature providers even if they share the same name. By transitioning from a map-based storage of providers to a list-based approach, the system can now accommodate scenarios where provider names are not unique. This change simplifies the internal architecture of the multi-provider, addressing potential issues with name collisions and enhancing flexibility, while acknowledging a minor trade-off in direct name-based provider retrieval within strategies.

Highlights

  • Provider Collection Type Change: The internal representation of feature providers within MultiProvider and its associated strategies has been changed from a Map<String, FeatureProvider> to a List<FeatureProvider>.
  • Support for Duplicate Provider Names: This modification enables the MultiProvider to handle multiple feature providers that may have the same name, resolving a previous limitation.
  • Simplified Provider Management: The buildProviders method, which previously managed name-based mapping and logged duplicate names, has been removed, streamlining the provider initialization process.
  • Metadata Structure Update: The MultiProviderMetadata now stores a List<Metadata> instead of a Map<String, Metadata> to reflect the change in how original provider metadata is tracked.
Changelog
  • src/main/java/dev/openfeature/sdk/multiprovider/FirstMatchStrategy.java
    • Updated the evaluate method signature to accept a List<FeatureProvider> instead of a Map<String, FeatureProvider>.
  • src/main/java/dev/openfeature/sdk/multiprovider/FirstSuccessfulStrategy.java
    • Modified the evaluate method signature to use a List<FeatureProvider> for providers.
  • src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java
    • Refactored provider storage from Map to List.
    • Removed the buildProviders helper method.
    • Adjusted initialization and shutdown logic to iterate over the List of providers.
  • src/main/java/dev/openfeature/sdk/multiprovider/MultiProviderMetadata.java
    • Changed the originalMetadata field type from Map<String, Metadata> to List<Metadata>.
  • src/main/java/dev/openfeature/sdk/multiprovider/Strategy.java
    • Updated the evaluate method in the interface to pass a List<FeatureProvider> to strategies.
  • src/test/java/dev/openfeature/sdk/multiprovider/BaseStrategyTest.java
    • Adapted test setup to use List for orderedProviders instead of Map.
  • src/test/java/dev/openfeature/sdk/multiprovider/FirstSuccessfulStrategyTest.java
    • Adjusted test cases to add providers to a List rather than a Map.
  • src/test/java/dev/openfeature/sdk/multiprovider/MultiProviderTest.java
    • Updated tests to reflect the List-based storage of providers and their metadata, including changes to assertions and provider retrieval in custom strategies.
Activity
  • No human activity has been recorded on this pull request yet.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sonarqubecloud

Copy link
Copy Markdown

@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 successfully refactors the MultiProvider to allow providers with identical names by switching from a Map to a List for storing providers. This is a well-documented breaking change for the experimental Strategy interface. The modifications are consistently applied throughout the affected classes and their corresponding tests. The test suite has been updated effectively to accommodate these changes. I've identified one minor area for improvement in a test case to enhance its robustness. Overall, the change is well-implemented.

@codecov

codecov Bot commented Feb 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.05%. Comparing base (602b5f4) to head (d5e3b1e).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1848      +/-   ##
============================================
+ Coverage     92.52%   93.05%   +0.53%     
+ Complexity      728      727       -1     
============================================
  Files            60       60              
  Lines          1739     1728      -11     
  Branches        202      200       -2     
============================================
- Hits           1609     1608       -1     
+ Misses           80       72       -8     
+ Partials         50       48       -2     
Flag Coverage Δ
unittests 93.05% <100.00%> (+0.53%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chrfwow chrfwow changed the title Allow for providers with equal name in the multiprovider feat: Allow for providers with equal name in the multiprovider Feb 11, 2026
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
@toddbaert
toddbaert force-pushed the allow-non-unique-provider-names branch from c2cb2b9 to 84e9870 Compare July 30, 2026 18:58
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b1908d5-7b75-4b4e-8f6c-fb36d5def1d5

📥 Commits

Reviewing files that changed from the base of the PR and between 84e9870 and d5e3b1e.

📒 Files selected for processing (2)
  • api-changes.json
  • src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java

📝 Walkthrough

Walkthrough

The multi-provider implementation now stores ordered FeatureProvider lists, derives provider names from metadata, and exposes original metadata as a list. Strategy contracts, lifecycle logic, API compatibility records, custom strategies, and tests were updated accordingly.

Changes

Multi-provider list migration

Layer / File(s) Summary
List-based contracts and metadata
src/main/java/dev/openfeature/sdk/multiprovider/Strategy.java, src/main/java/dev/openfeature/sdk/multiprovider/MultiProviderMetadata.java, api-changes.json
Strategy evaluation accepts provider lists, original provider metadata is exposed as a list, and the API difference is recorded.
Provider storage and lifecycle
src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java
Provider storage, initialization, metadata aggregation, and shutdown iterate over the ordered list.
Strategy evaluation and validation
src/main/java/dev/openfeature/sdk/multiprovider/*Strategy.java, src/test/java/dev/openfeature/sdk/multiprovider/*
Built-in strategies derive provider names from metadata, while tests use list-based providers and metadata assertions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • open-feature/java-sdk#1982: Both changes update MultiProvider provider iteration and metadata aggregation over the underlying provider collection.

Suggested reviewers: aepfli, toddbaert

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: supporting multiple providers with the same name in MultiProvider.
Description check ✅ Passed The description is directly related to the PR and explains the duplicate-name MultiProvider change.
Linked Issues check ✅ Passed The PR changes originalMetadata from a map to a list, which directly addresses issue #1792's request to reconsider that type.
Out of Scope Changes check ✅ Passed The changes all support the duplicate-provider-name MultiProvider refactor and do not show unrelated additions.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/main/java/dev/openfeature/sdk/multiprovider/MultiProviderMetadata.java (2)

11-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document ordering and duplicate preservation.

State that originalMetadata follows provider-list order and retains duplicate entries; consumers otherwise cannot safely associate metadata with providers sharing a name.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/dev/openfeature/sdk/multiprovider/MultiProviderMetadata.java`
around lines 11 - 12, Update the documentation for MultiProviderMetadata to
specify that originalMetadata is ordered according to the underlying provider
list and preserves duplicate entries, allowing consumers to associate metadata
with providers that share a name.

19-19: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Defensively copy originalMetadata at construction.

@Value makes the reference final, not the List contents. A caller using the builder can mutate the list after construction, changing metadata returned by getOriginalMetadata(). Copy the collection at the value-object boundary.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/dev/openfeature/sdk/multiprovider/MultiProviderMetadata.java`
at line 19, Defensively copy originalMetadata in the MultiProviderMetadata
construction path so the stored list cannot be mutated through the builder’s
input after construction. Preserve the existing metadata values and getter
behavior while ensuring the value object owns an independent collection.
src/test/java/dev/openfeature/sdk/multiprovider/MultiProviderTest.java (1)

57-59: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the complete metadata list.

contains does not verify ordering or cardinality; incorrect aggregation, reordering, or dropped entries could still pass. Compare against the expected list directly and add a duplicate-name case.

Proposed test adjustment
-        List<Metadata> list = metadata.getOriginalMetadata();
-        assertTrue(list.contains(mockMetaData1));
-        assertTrue(list.contains(mockMetaData2));
+        assertEquals(List.of(mockMetaData1, mockMetaData2), metadata.getOriginalMetadata());

-        List<Metadata> list = metadata.getOriginalMetadata();
-        assertTrue(list.contains(mockMetaData1));
+        assertEquals(List.of(mockMetaData1), metadata.getOriginalMetadata());

Also applies to: 169-170

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/java/dev/openfeature/sdk/multiprovider/MultiProviderTest.java`
around lines 57 - 59, Update the metadata assertions in MultiProviderTest to
compare getOriginalMetadata() directly with the expected ordered list,
validating both contents and cardinality rather than using individual contains
checks. Extend the test with duplicate-name metadata entries to verify
aggregation retains all entries and preserves their expected order.
src/main/java/dev/openfeature/sdk/multiprovider/FirstSuccessfulStrategy.java (1)

27-35: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover duplicate names in strategy evaluation.

This migration is intended to preserve multiple providers with the same metadata name, but strategy tests currently use unique names. Add equivalent coverage for both strategies with duplicate names and assert that both providers are evaluated and retained in error order.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/dev/openfeature/sdk/multiprovider/FirstSuccessfulStrategy.java`
around lines 27 - 35, Add strategy tests covering providers with duplicate
metadata names for both evaluation strategies, ensuring each provider is invoked
and both resulting errors are retained in their evaluation order. Use the
existing provider-function and error-collection assertions, changing only
provider names and expectations needed to verify duplicates are not collapsed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java`:
- Around line 58-60: Update the MultiProvider constructor to store an
unmodifiable defensive copy of the supplied providers list rather than retaining
the caller’s mutable list. Preserve the list’s original order and duplicate
entries, and keep strategy initialization, lifecycle operations, and evaluations
using this stable snapshot.

In `@src/main/java/dev/openfeature/sdk/multiprovider/Strategy.java`:
- Line 37: Update the `@param` providers documentation for the affected method in
Strategy to describe the List<FeatureProvider> accurately: state that provider
order is significant and duplicate provider names are preserved, removing the
outdated “ordered map” wording.

---

Nitpick comments:
In
`@src/main/java/dev/openfeature/sdk/multiprovider/FirstSuccessfulStrategy.java`:
- Around line 27-35: Add strategy tests covering providers with duplicate
metadata names for both evaluation strategies, ensuring each provider is invoked
and both resulting errors are retained in their evaluation order. Use the
existing provider-function and error-collection assertions, changing only
provider names and expectations needed to verify duplicates are not collapsed.

In `@src/main/java/dev/openfeature/sdk/multiprovider/MultiProviderMetadata.java`:
- Around line 11-12: Update the documentation for MultiProviderMetadata to
specify that originalMetadata is ordered according to the underlying provider
list and preserves duplicate entries, allowing consumers to associate metadata
with providers that share a name.
- Line 19: Defensively copy originalMetadata in the MultiProviderMetadata
construction path so the stored list cannot be mutated through the builder’s
input after construction. Preserve the existing metadata values and getter
behavior while ensuring the value object owns an independent collection.

In `@src/test/java/dev/openfeature/sdk/multiprovider/MultiProviderTest.java`:
- Around line 57-59: Update the metadata assertions in MultiProviderTest to
compare getOriginalMetadata() directly with the expected ordered list,
validating both contents and cardinality rather than using individual contains
checks. Extend the test with duplicate-name metadata entries to verify
aggregation retains all entries and preserves their expected order.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3f56b200-c35c-4311-8636-6d7c94743fee

📥 Commits

Reviewing files that changed from the base of the PR and between 602b5f4 and 84e9870.

📒 Files selected for processing (8)
  • src/main/java/dev/openfeature/sdk/multiprovider/FirstMatchStrategy.java
  • src/main/java/dev/openfeature/sdk/multiprovider/FirstSuccessfulStrategy.java
  • src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java
  • src/main/java/dev/openfeature/sdk/multiprovider/MultiProviderMetadata.java
  • src/main/java/dev/openfeature/sdk/multiprovider/Strategy.java
  • src/test/java/dev/openfeature/sdk/multiprovider/BaseStrategyTest.java
  • src/test/java/dev/openfeature/sdk/multiprovider/FirstSuccessfulStrategyTest.java
  • src/test/java/dev/openfeature/sdk/multiprovider/MultiProviderTest.java

Comment on lines 58 to 60
this.providers = providers;
this.strategy = Objects.requireNonNull(strategy, "strategy must not be null");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
fd -a 'MultiProvider\.java|.*Provider.*\.java' . | sed 's#^\./##' | head -50

echo "== MultiProvider outline and relevant source =="
if [ -f src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java ]; then
  wc -l src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java
  ast-grep outline src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java || true
  cat -n src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java
else
  echo "MultiProvider.java not found at expected path"
fi

echo "== usages / references =="
rg -n "MultiProvider|providers|strategy" src/main/java/dev/openfeature/sdk -S || true

echo "== behavioral probe: direct retention and mutation impact =="
python3 - <<'PY'
import re, pathlib
p = pathlib.Path('src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java')
s = p.read_text()
checks = {
  "constructor_stores_providers_directly": "this.providers = providers" in s,
  "initializes_unmodifiable_metadata": "unmodifiableList" in s and "providerMetadata" in s,
  "passes_providers_to_strategy": bool(re.search(r'strategy\s*=\s*.*provider.*\)', s, re.S)) or 'providers' in s and 'strategy' in s,
}
print(checks)
# Minimal Java-ish simulation of retaining a caller's mutable list and later mutation.
providers = ["A", "B"]
metadata = [f"{p}/meta" for p in providers]
providers.append("C")
print(metadata)
try:
    for p in providers:
        print(p)
        providers.remove("B")
except RuntimeError as e:
    print("mutation_while_iterating_error_type=", type(e).__name__)
PY

Repository: open-feature/java-sdk

Length of output: 22557


Snapshot the provider list in the constructor.

MultiProvider retains the caller-supplied mutable list and passes it to strategies during evaluations. If callers mutate the list later, initialization results can diverge from lifecycle operations or evaluation behavior, and concurrent iteration can fail. Preserve duplicates and order while storing an unmodifiable defensive copy.

Proposed fix
-        this.providers = providers;
+        this.providers = Collections.unmodifiableList(
+                new ArrayList<>(Objects.requireNonNull(providers, "providers must not be null")));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.providers = providers;
this.strategy = Objects.requireNonNull(strategy, "strategy must not be null");
}
this.providers = Collections.unmodifiableList(
new ArrayList<>(Objects.requireNonNull(providers, "providers must not be null")));
this.strategy = Objects.requireNonNull(strategy, "strategy must not be null");
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/dev/openfeature/sdk/multiprovider/MultiProvider.java` around
lines 58 - 60, Update the MultiProvider constructor to store an unmodifiable
defensive copy of the supplied providers list rather than retaining the caller’s
mutable list. Preserve the list’s original order and duplicate entries, and keep
strategy initialization, lifecycle operations, and evaluations using this stable
snapshot.

*/
<T> ProviderEvaluation<T> evaluate(
Map<String, FeatureProvider> providers,
List<FeatureProvider> providers,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the provider parameter documentation.

The @param providers text at Line 28 still says “ordered map,” although this method now receives a List<FeatureProvider>. Document that list order is significant and duplicate provider names are preserved.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/dev/openfeature/sdk/multiprovider/Strategy.java` at line 37,
Update the `@param` providers documentation for the affected method in Strategy to
describe the List<FeatureProvider> accurately: state that provider order is
significant and duplicate provider names are preserved, removing the outdated
“ordered map” wording.

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@sonarqubecloud

Copy link
Copy Markdown

@toddbaert toddbaert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is breaking - approved in spirit, blocking for now but will release with manually edited notes.

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.

[Multi-provider] Reconsider type of "originalMetadata"

2 participants