diff --git a/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java b/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java index ca67ccfbaa..a910e408c1 100644 --- a/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java +++ b/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java @@ -301,7 +301,7 @@ public class DefaultPromise extends AbstractFuture implements Promise { @Override public V getNow() { Object result = this.result; - if (result instanceof CauseHolder || result == SUCCESS) { + if (result instanceof CauseHolder || result == SUCCESS || result == UNCANCELLABLE) { return null; } return (V) result; diff --git a/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java b/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java index 9c29f94a55..fd9a3e95d6 100644 --- a/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java +++ b/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java @@ -37,10 +37,7 @@ import java.util.concurrent.atomic.AtomicInteger; import static java.lang.Math.max; import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; @SuppressWarnings("unchecked") public class DefaultPromiseTest { @@ -258,6 +255,22 @@ public class DefaultPromiseTest { assertTrue(promise.isSuccess()); } + @Test + public void setUncancellableGetNow() { + final Promise promise = new DefaultPromise(ImmediateEventExecutor.INSTANCE); + assertNull(promise.getNow()); + assertTrue(promise.setUncancellable()); + assertNull(promise.getNow()); + assertFalse(promise.isDone()); + assertFalse(promise.isSuccess()); + + promise.setSuccess("success"); + + assertTrue(promise.isDone()); + assertTrue(promise.isSuccess()); + assertEquals("success", promise.getNow()); + } + private static void testStackOverFlowChainedFuturesA(int promiseChainLength, final EventExecutor executor, boolean runTestInExecutorThread) throws InterruptedException {