Skip to content

Commit ee04bd2

Browse files
yorickhenningqwwdfsad
authored andcommitted
Hid the SettableFuture of future {}.
This should prevent successful casts to type SettableFuture, meaning client code can't access and complete the internal Future without resorting to reflection..
1 parent 8f39109 commit ee04bd2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

integration/kotlinx-coroutines-guava/src/ListenableFuture.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public fun <T> CoroutineScope.future(
4646
): ListenableFuture<T> {
4747
require(!start.isLazy) { "$start start is not supported" }
4848
val newContext = newCoroutineContext(context)
49-
// TODO: It'd be nice not to leak this SettableFuture reference, which is easily blind-cast.
5049
val future = SettableFuture.create<T>()
5150
val coroutine = ListenableFutureCoroutine(newContext, future)
5251
future.addListener(
5352
coroutine,
5453
MoreExecutors.directExecutor())
5554
coroutine.start(start, coroutine, block)
56-
return future
55+
// Return hides the SettableFuture. This should prevent casting.
56+
return object: ListenableFuture<T> by future {}
5757
}
5858

5959
/**

0 commit comments

Comments
 (0)