Skip to content

Commit 0bc5d21

Browse files
authored
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 (#1868)
Fixes #1866
2 parents a25bf36 + cfb3ff9 commit 0bc5d21

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

kotlinx-coroutines-core/jvm/src/Exceptions.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ internal actual class JobCancellationException public actual constructor(
4040
if (DEBUG) {
4141
return super.fillInStackTrace()
4242
}
43-
43+
// Prevent Android <= 6.0 bug, #1866
44+
stackTrace = emptyArray()
4445
/*
4546
* In non-debug mode we don't want to have a stacktrace on every cancellation/close,
4647
* parent job reference is enough. Stacktrace of JCE is not needed most of the time (e.g., it is not logged)

kotlinx-coroutines-core/jvm/src/flow/internal/FlowExceptions.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ internal actual class AbortFlowException actual constructor(
1212
) : CancellationException("Flow was aborted, no more elements needed") {
1313

1414
override fun fillInStackTrace(): Throwable {
15-
if (DEBUG) super.fillInStackTrace()
15+
if (DEBUG) return super.fillInStackTrace()
16+
// Prevent Android <= 6.0 bug, #1866
17+
stackTrace = emptyArray()
1618
return this
1719
}
1820
}
1921

2022
internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled") {
2123
override fun fillInStackTrace(): Throwable {
22-
if (DEBUG) super.fillInStackTrace()
24+
if (DEBUG) return super.fillInStackTrace()
25+
// Prevent Android <= 6.0 bug, #1866
26+
stackTrace = emptyArray()
2327
return this
2428
}
2529
}

0 commit comments

Comments
 (0)