Skip to content

Commit

Permalink
Fix logic that determines future removal for scheduled executors (Kot…
Browse files Browse the repository at this point in the history
…lin#1995)

I've failed to write a reliable test here. See also Kotlin#571

Fixes Kotlin#1992
  • Loading branch information
elizarov authored and recheej committed Dec 28, 2020
1 parent c253929 commit aab779b
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 aab779b

Please sign in to comment.