Skip to content

Commit

Permalink
Fix logic that determines future removal for scheduled executors (#1995)
Browse files Browse the repository at this point in the history
I've failed to write a reliable test here. See also #571

Fixes #1992
  • Loading branch information
elizarov authored May 7, 2020
1 parent 18f68ad commit 5ecebe1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ private val REMOVE_FUTURE_ON_CANCEL: Method? = try {
@Suppress("NAME_SHADOWING")
internal fun removeFutureOnCancel(executor: Executor): Boolean {
try {
val executor = executor as? ScheduledExecutorService ?: return false
val executor = executor as? ScheduledThreadPoolExecutor ?: return false
(REMOVE_FUTURE_ON_CANCEL ?: return false).invoke(executor, true)
return true
} catch (e: Throwable) {
return true
return false // failed to setRemoveOnCancelPolicy, assume it does not removes future on cancel
}
}

0 comments on commit 5ecebe1

Please sign in to comment.