Skip to content

Commit

Permalink
fix: pass empty contexts rather than null to UniAwait
Browse files Browse the repository at this point in the history
When no context is specified, Context.empty() must be used rather than null.

Fixes #1457
  • Loading branch information
jponge committed Dec 7, 2023
1 parent 8429724 commit 303bdab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public UniOnItemOrFailure<T> onItemOrFailure() {

@Override
public UniAwait<T> await() {
return awaitUsing(null);
return awaitUsing(Context.empty());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,20 @@ void checkForbid() throws InterruptedException {
.isInstanceOf(IllegalStateException.class)
.hasMessage("The current thread cannot be blocked: my-forbidden-thread");
}

@Test
void checkImplicitContextPassing() {
AtomicBoolean contextPassed = new AtomicBoolean();
Integer res = Uni.createFrom().item(123)
.withContext((uni, ctx) -> {
ctx.put("foo", "bar");
return uni;
})
.withContext((uni, ctx) -> uni.onItem()
.invoke(() -> contextPassed.set(ctx.getOrElse("foo", () -> "n/a").equals("bar"))))
.await().indefinitely();
assertThat(res).isEqualTo(123);
assertThat(contextPassed).isTrue();
}
}
}

0 comments on commit 303bdab

Please sign in to comment.