Skip to content

NullPointerException in Future.await #4972

@magicprinc

Description

@magicprinc

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: #4958

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions