Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in Future.await #4972

Open
magicprinc opened this issue Nov 26, 2023 · 0 comments · Fixed by #4973
Open

NullPointerException in Future.await #4972

magicprinc opened this issue Nov 26, 2023 · 0 comments · Fixed by #4973
Labels

Comments

@magicprinc
Copy link
Contributor

magicprinc commented Nov 26, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant