Skip to content

Fix NRE bug when accessing client instance during client initialization#116

Merged
adams85 merged 3 commits intomasterfrom
fix/client-init-hook-bug
Aug 8, 2025
Merged

Fix NRE bug when accessing client instance during client initialization#116
adams85 merged 3 commits intomasterfrom
fix/client-init-hook-bug

Conversation

@adams85
Copy link
Contributor

@adams85 adams85 commented Aug 4, 2025

Describe the purpose of your pull request

The SDK has a long-standing bug that occurs when the client instance is used in a hook event handler during client initialization. For example, a setup like

ConfigCatClient.Get("SDK-KEY", options =>
{
    options.ConfigChanged += (s, e) => snapshot = ((IConfigCatClient)s!).GetValue(...);
});      

blows up when up-to-date config data is already available in the cache because in that case the event is raised before all fields are initialized in ConfigCatClient . A call like GetValue accesses those fields, resulting in a NullReferenceException exception.

This PR fixes this issue.

Related issues (only if applicable)

n/a

How to test? (only if applicable)

n/a

Security (only if applicable)

n/a

Requirement checklist (only if applicable)

  • I have covered the applied changes with automated tests.
  • I have executed the full automated test set against my changes.
  • I have validated my changes against all supported platform versions.
  • I have read and accepted the contribution agreement.

@adams85 adams85 requested a review from a team as a code owner August 4, 2025 07:57
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 4, 2025

@adams85 adams85 changed the title Fix accessing client instance during client initialization Fix NRE bug when accessing client instance during client initialization Aug 4, 2025
@adams85 adams85 merged commit 1cdafea into master Aug 8, 2025
17 checks passed
@adams85 adams85 deleted the fix/client-init-hook-bug branch August 8, 2025 16:06
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