-
Notifications
You must be signed in to change notification settings - Fork 52
fix: Fix StackOverflow on recursive contexts #1760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||
| package dev.openfeature.sdk; | ||||||||||
|
|
||||||||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||||||||
| import static org.assertj.core.api.Assertions.assertThatNoException; | ||||||||||
| import static org.mockito.ArgumentMatchers.any; | ||||||||||
| import static org.mockito.Mockito.mock; | ||||||||||
| import static org.mockito.Mockito.verify; | ||||||||||
|
|
@@ -113,6 +114,29 @@ void shouldIsolateDataBetweenHooks(FlagValueType flagValueType) { | |||||||||
| assertHookData(testHook2, 2, "before", "after", "finallyAfter", "error"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Test | ||||||||||
| void hookThatReturnsTheGivenContext_doesNotResultInAStackOverflow() { | ||||||||||
| var hookSupportData = new HookSupportData(); | ||||||||||
| var recursiveHook = new Hook() { | ||||||||||
| @Override | ||||||||||
| public Optional<EvaluationContext> before(HookContext ctx, Map hints) { | ||||||||||
| return Optional.of(ctx.getCtx()); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
| var layeredEvaluationContext = | ||||||||||
| new LayeredEvaluationContext(evaluationContextWithValue("key", "value"), null, null, null); | ||||||||||
| hookSupportData.evaluationContext = layeredEvaluationContext; | ||||||||||
| hookSupport.setHooks(hookSupportData, List.of(recursiveHook), FlagValueType.STRING); | ||||||||||
| hookSupport.setHookContexts( | ||||||||||
| hookSupportData, getBaseHookContextForType(FlagValueType.STRING), layeredEvaluationContext); | ||||||||||
|
|
||||||||||
| callAllHooks(hookSupportData); | ||||||||||
|
|
||||||||||
| layeredEvaluationContext.asObjectMap(); | ||||||||||
|
|
||||||||||
| assertThatNoException(); | ||||||||||
|
||||||||||
| layeredEvaluationContext.asObjectMap(); | |
| assertThatNoException(); | |
| assertThatNoException().isThrownBy(layeredEvaluationContext::asObjectMap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Q] would java optimize this anyway or could this be a slight improvement checking for empty first?