From 38067db5e6b9672984cd542acfe02da7284c0cd7 Mon Sep 17 00:00:00 2001 From: Roman Elizarov Date: Wed, 6 May 2020 15:25:39 +0300 Subject: [PATCH] Fix logic that determines future removal for scheduled executors I've failed to write a reliable test here. See also #571 Fixes #1992 --- kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt b/kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt index 171748ff68..75b668a335 100644 --- a/kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt +++ b/kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt @@ -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 } }