vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

NullPointerException in Future.await

Open magicprinc opened this issue 2 years ago • 0 comments

How to reproduce: interrupt the waiting thread in the middle of CountDownLatch.await

    try {
      cont.suspendAndAwaitResume();
    } catch (InterruptedException e) {
      Utils.throwAsUnchecked(e.getCause());
      return null;
    }

InterruptedException.cause is null. throw null produces NPE.

PS:

Utils.throwAsUnchecked(e.getCause());
return null;

can also be optimized into one line

public static <E extends Throwable> **RuntimeException** throwAsUnchecked(Throwable t) throws E {
  throw (E) t;
}

after it, use:

throw Utils.throwAsUnchecked(e);

PPS: and "happy path" for aready competed Futures

default T await() {
    if (isComplete()) {
      return ...
    }

PR: https://github.com/eclipse-vertx/vert.x/pull/4958

magicprinc avatar Nov 26 '23 13:11 magicprinc