fix: make openFeatureProvider an instance field instead of static#187
fix: make openFeatureProvider an instance field instead of static#187jonathannorris merged 3 commits intomainfrom
Conversation
The static field caused all DevCycleLocalClient instances to share the same DevCycleProvider, which is incorrect when clients have different configurations. This aligns with DevCycleCloudClient's implementation.
There was a problem hiding this comment.
Pull request overview
This PR fixes a design issue where the openFeatureProvider field in DevCycleLocalClient was incorrectly declared as static, causing all client instances to share the same provider. The fix changes it to an instance field so each client has its own provider, and removes the now-unnecessary class-level synchronization.
Changes:
- Changed
openFeatureProviderfrom static to instance field inDevCycleLocalClient - Removed class-level synchronized block that was protecting the static field initialization
- Simplified the lazy initialization logic while maintaining the platform data setup
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/com/devcycle/sdk/server/local/api/DevCycleLocalClient.java
Show resolved
Hide resolved
Use volatile + double-checked locking to prevent race condition when multiple threads call getOpenFeatureProvider() concurrently.
Use synchronized method instead of volatile + double-checked locking. Set platform data on every call rather than only on first access.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix static OpenFeatureProvider field in DevCycleLocalClient
Problem
DevCycleLocalClientused astaticfield foropenFeatureProvider, causing all client instances to share the same provider. This is incorrect when clients have different configurations.Solution
Changed
openFeatureProviderfrom a static field to an instance field, and added thread-safe lazy initialization.Changes
private static DevCycleProvider→private DevCycleProvider(instance field)synchronizedtogetOpenFeatureProvider()method for thread safetygetOpenFeatureProvider()to ensure correct SDK trackingThread Safety
The
synchronizedmethod ensures that only oneDevCycleProviderinstance is created per client, even when multiple threads callgetOpenFeatureProvider()concurrently.