Skip to content

Commit

Permalink
Fill in stacktrace of cancellation exception with an empty array to p…
Browse files Browse the repository at this point in the history
…roperly work on Android <= 6.0 that had a bug on a code-path with an empty stacktrace

Fixes #1866
  • Loading branch information
qwwdfsad committed Mar 16, 2020
1 parent a25bf36 commit cfb3ff9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kotlinx-coroutines-core/jvm/src/Exceptions.kt
Expand Up @@ -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)
Expand Down
Expand Up @@ -12,14 +12,18 @@ internal actual class AbortFlowException actual constructor(
) : CancellationException("Flow was aborted, no more elements needed") {

override fun fillInStackTrace(): Throwable {
if (DEBUG) super.fillInStackTrace()
if (DEBUG) return super.fillInStackTrace()
// Prevent Android <= 6.0 bug, #1866
stackTrace = emptyArray()
return this
}
}

internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled") {
override fun fillInStackTrace(): Throwable {
if (DEBUG) super.fillInStackTrace()
if (DEBUG) return super.fillInStackTrace()
// Prevent Android <= 6.0 bug, #1866
stackTrace = emptyArray()
return this
}
}

0 comments on commit cfb3ff9

Please sign in to comment.