Skip to content

Commit

Permalink
Hid the SettableFuture of future {}.
Browse files Browse the repository at this point in the history
This should prevent successful casts to type SettableFuture, meaning
client code can't access and complete the internal Future without
resorting to reflection..
  • Loading branch information
yorickhenning authored and qwwdfsad committed Sep 25, 2019
1 parent 8f39109 commit ee04bd2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions integration/kotlinx-coroutines-guava/src/ListenableFuture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public fun <T> CoroutineScope.future(
): ListenableFuture<T> {
require(!start.isLazy) { "$start start is not supported" }
val newContext = newCoroutineContext(context)
// TODO: It'd be nice not to leak this SettableFuture reference, which is easily blind-cast.
val future = SettableFuture.create<T>()
val coroutine = ListenableFutureCoroutine(newContext, future)
future.addListener(
coroutine,
MoreExecutors.directExecutor())
coroutine.start(start, coroutine, block)
return future
// Return hides the SettableFuture. This should prevent casting.
return object: ListenableFuture<T> by future {}
}

/**
Expand Down

0 comments on commit ee04bd2

Please sign in to comment.