From d1ca054e473a93d70062782140338fa672b08efc Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Mon, 16 Mar 2020 12:36:08 +0300 Subject: [PATCH] Fill in stacktrace of cancellation exception with an empty array to properly work on Android <= 6.0 that had a bug on a code-path with an empty stacktrace Fixes #1866 --- kotlinx-coroutines-core/jvm/src/Exceptions.kt | 3 ++- .../jvm/src/flow/internal/FlowExceptions.kt | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kotlinx-coroutines-core/jvm/src/Exceptions.kt b/kotlinx-coroutines-core/jvm/src/Exceptions.kt index 22a02a30bb..0684ce2397 100644 --- a/kotlinx-coroutines-core/jvm/src/Exceptions.kt +++ b/kotlinx-coroutines-core/jvm/src/Exceptions.kt @@ -40,7 +40,8 @@ internal actual class JobCancellationException public actual constructor( if (DEBUG) { return super.fillInStackTrace() } - + // Prevent Android <= 6.0 bug, #1866 + stackTrace = emptyArray() /* * In non-debug mode we don't want to have a stacktrace on every cancellation/close, * parent job reference is enough. Stacktrace of JCE is not needed most of the time (e.g., it is not logged) diff --git a/kotlinx-coroutines-core/jvm/src/flow/internal/FlowExceptions.kt b/kotlinx-coroutines-core/jvm/src/flow/internal/FlowExceptions.kt index 863c2cc4ab..1cba220f4b 100644 --- a/kotlinx-coroutines-core/jvm/src/flow/internal/FlowExceptions.kt +++ b/kotlinx-coroutines-core/jvm/src/flow/internal/FlowExceptions.kt @@ -13,6 +13,8 @@ internal actual class AbortFlowException actual constructor( override fun fillInStackTrace(): Throwable { if (DEBUG) super.fillInStackTrace() + // Prevent Android <= 6.0 bug, #1866 + stackTrace = emptyArray() return this } } @@ -20,6 +22,8 @@ internal actual class AbortFlowException actual constructor( internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled") { override fun fillInStackTrace(): Throwable { if (DEBUG) super.fillInStackTrace() + // Prevent Android <= 6.0 bug, #1866 + stackTrace = emptyArray() return this } }