You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many JDK methods that return CompletionStage are internally implemented using a class called MinimalStage, which inherits implementation from CompletableFuture (and therefore extends Future at runtime) but throws UnsupportedOperationException at runtime for most Future methods e.g. isDone(). Provided the caller uses the declared return type of CompletionStage this doesn't matter.
Unfortunately CompletionStage<T>.await() checks reflectively whether the passed CompletionStage implements Future and then calls Future#isDone() if it does, leading to an exception like:
java.lang.UnsupportedOperationException
at java.base/java.util.concurrent.CompletableFuture$MinimalStage.isDone(CompletableFuture.java:2844)
at kotlinx.coroutines.future.FutureKt.await(Future.kt:150)
Minimal reproduction (tested on JDK11):
import java.util.concurrent.CompletableFuture
import kotlinx.coroutines.future.await
suspend fun main() {
CompletableFuture.completedStage(Unit).await()
println("Hello World") // never called
}
The text was updated successfully, but these errors were encountered:
Many JDK methods that return
CompletionStage
are internally implemented using a class calledMinimalStage
, which inherits implementation fromCompletableFuture
(and therefore extendsFuture
at runtime) but throwsUnsupportedOperationException
at runtime for mostFuture
methods e.g.isDone()
. Provided the caller uses the declared return type ofCompletionStage
this doesn't matter.Unfortunately
CompletionStage<T>.await()
checks reflectively whether the passedCompletionStage
implementsFuture
and then callsFuture#isDone()
if it does, leading to an exception like:Minimal reproduction (tested on JDK11):
The text was updated successfully, but these errors were encountered: