Skip to content

fix: guard against nil ContextEvaluator func in memprovider Resolve#522

Open
somaz94 wants to merge 1 commit into
open-feature:mainfrom
somaz94:fix/memprovider-nil-context-evaluator
Open

fix: guard against nil ContextEvaluator func in memprovider Resolve#522
somaz94 wants to merge 1 commit into
open-feature:mainfrom
somaz94:fix/memprovider-nil-context-evaluator

Conversation

@somaz94

@somaz94 somaz94 commented Jul 7, 2026

Copy link
Copy Markdown

memprovider.InMemoryFlag.ContextEvaluator is typed *func(...). Resolve
only checked the pointer for nil, so a non-nil pointer to a nil func passed the
guard and panicked on the dereference-and-call. This adds the missing inner
nil-func check so such a flag falls back to the default variant, plus a
regression test.

Fixes #521

Validation:

  • make test (go test -tags testtools -race): all packages pass, memprovider at 86.9% coverage
  • make lint (golangci-lint v2.9.0): 0 issues
  • Confirmed the new test panics against the old guard and passes with the fix

Signed-off-by: somaz <genius5711@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 7, 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: acfd78f5-08c1-4116-8099-9e74263118bd

📥 Commits

Reviewing files that changed from the base of the PR and between e75753b and d7ee7b6.

📒 Files selected for processing (2)
  • openfeature/memprovider/in_memory_provider.go
  • openfeature/memprovider/in_memory_provider_test.go

📝 Walkthrough

Walkthrough

Modified InMemoryFlag.Resolve in the memprovider package to check both the ContextEvaluator pointer and the underlying function value for nil before invoking it, preventing a nil-pointer dereference panic. Added a regression test verifying fallback to DefaultVariant when ContextEvaluator points to a nil function.

Changes

ContextEvaluator nil guard

Layer / File(s) Summary
Nil-function guard and regression test
openfeature/memprovider/in_memory_provider.go, openfeature/memprovider/in_memory_provider_test.go
Resolve now checks that both the ContextEvaluator pointer and the function it references are non-nil before calling it; a new test confirms the flag falls back to its DefaultVariant with StaticReason instead of panicking when given a non-nil pointer to a nil function.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the nil ContextEvaluator guard fix in memprovider Resolve.
Description check ✅ Passed The description matches the code change and regression test for the nil ContextEvaluator case.
Linked Issues check ✅ Passed The change implements #521 by checking the underlying func for nil and falling back to the default variant.
Out of Scope Changes check ✅ Passed The PR only touches the bug fix and its regression test, with no apparent unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@somaz94 somaz94 marked this pull request as ready for review July 9, 2026 02:53
@somaz94 somaz94 requested review from a team as code owners July 9, 2026 02:53
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.

[BUG] memprovider.ContextEvaluator nil-check is insufficient — non-nil pointer to nil function panics

1 participant