From aab779ba0821f5289cd8f6f2f092224551b28de1 Mon Sep 17 00:00:00 2001 From: Roman Elizarov Date: Thu, 7 May 2020 16:57:16 +0300 Subject: [PATCH] Fix logic that determines future removal for scheduled executors (#1995) 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 } }