From 303bdab75e07614e68c804d432632085b7e677ba Mon Sep 17 00:00:00 2001 From: Julien Ponge Date: Thu, 7 Dec 2023 09:26:49 +0100 Subject: [PATCH] fix: pass empty contexts rather than null to UniAwait When no context is specified, Context.empty() must be used rather than null. Fixes #1457 --- .../io/smallrye/mutiny/operators/AbstractUni.java | 2 +- .../smallrye/mutiny/operators/UniAwaitTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractUni.java b/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractUni.java index eed2551c7..ccfe8be87 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractUni.java +++ b/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractUni.java @@ -81,7 +81,7 @@ public UniOnItemOrFailure onItemOrFailure() { @Override public UniAwait await() { - return awaitUsing(null); + return awaitUsing(Context.empty()); } @Override diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/UniAwaitTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/UniAwaitTest.java index 5d39e7aec..f037254b4 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/UniAwaitTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/UniAwaitTest.java @@ -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(); + } } }