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

CompletionStage<T>.await() is broken for MinimalStage #2456

Closed
m50d opened this issue Dec 18, 2020 · 0 comments
Closed

CompletionStage<T>.await() is broken for MinimalStage #2456

m50d opened this issue Dec 18, 2020 · 0 comments
Assignees
Labels

Comments

@m50d
Copy link

m50d commented Dec 18, 2020

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
}
@elizarov elizarov added the bug label Dec 18, 2020
@elizarov elizarov self-assigned this Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants