@@ -33,16 +33,16 @@ private val stackTraceRecoveryClassName = runCatching {
33
33
internal actual fun <E : Throwable > recoverStackTrace (exception : E ): E {
34
34
if (! RECOVER_STACK_TRACES ) return exception
35
35
// No unwrapping on continuation-less path: exception is not reported multiple times via slow paths
36
- val copy = tryCopyAndVerify (exception) ? : return exception
36
+ val copy = tryCopyException (exception) ? : return exception
37
37
return copy.sanitizeStackTrace()
38
38
}
39
39
40
40
private fun <E : Throwable > E.sanitizeStackTrace (): E {
41
41
val stackTrace = stackTrace
42
42
val size = stackTrace.size
43
- val lastIntrinsic = stackTrace.frameIndex( stackTraceRecoveryClassName)
43
+ val lastIntrinsic = stackTrace.indexOfLast { stackTraceRecoveryClassName == it.className }
44
44
val startIndex = lastIntrinsic + 1
45
- val endIndex = stackTrace.frameIndex (baseContinuationImplClassName)
45
+ val endIndex = stackTrace.firstFrameIndex (baseContinuationImplClassName)
46
46
val adjustment = if (endIndex == - 1 ) 0 else size - endIndex
47
47
val trace = Array (size - lastIntrinsic - adjustment) {
48
48
if (it == 0 ) {
@@ -70,7 +70,7 @@ private fun <E : Throwable> recoverFromStackFrame(exception: E, continuation: Co
70
70
val (cause, recoveredStacktrace) = exception.causeAndStacktrace()
71
71
72
72
// Try to create an exception of the same type and get stacktrace from continuation
73
- val newException = tryCopyAndVerify (cause) ? : return exception
73
+ val newException = tryCopyException (cause) ? : return exception
74
74
// Update stacktrace
75
75
val stacktrace = createStackTrace(continuation)
76
76
if (stacktrace.isEmpty()) return exception
@@ -82,14 +82,6 @@ private fun <E : Throwable> recoverFromStackFrame(exception: E, continuation: Co
82
82
return createFinalException(cause, newException, stacktrace)
83
83
}
84
84
85
- private fun <E : Throwable > tryCopyAndVerify (exception : E ): E ? {
86
- val newException = tryCopyException(exception) ? : return null
87
- // Verify that the new exception has the same message as the original one (bail out if not, see #1631)
88
- // CopyableThrowable has control over its message and thus can modify it the way it wants
89
- if (exception !is CopyableThrowable <* > && newException.message != exception.message) return null
90
- return newException
91
- }
92
-
93
85
/*
94
86
* Here we partially copy original exception stackTrace to make current one much prettier.
95
87
* E.g. for
@@ -109,7 +101,7 @@ private fun <E : Throwable> tryCopyAndVerify(exception: E): E? {
109
101
private fun <E : Throwable > createFinalException (cause : E , result : E , resultStackTrace : ArrayDeque <StackTraceElement >): E {
110
102
resultStackTrace.addFirst(ARTIFICIAL_FRAME )
111
103
val causeTrace = cause.stackTrace
112
- val size = causeTrace.frameIndex (baseContinuationImplClassName)
104
+ val size = causeTrace.firstFrameIndex (baseContinuationImplClassName)
113
105
if (size == - 1 ) {
114
106
result.stackTrace = resultStackTrace.toTypedArray()
115
107
return result
@@ -157,7 +149,6 @@ private fun mergeRecoveredTraces(recoveredStacktrace: Array<StackTraceElement>,
157
149
}
158
150
}
159
151
160
- @Suppress(" NOTHING_TO_INLINE" )
161
152
internal actual suspend inline fun recoverAndThrow (exception : Throwable ): Nothing {
162
153
if (! RECOVER_STACK_TRACES ) throw exception
163
154
suspendCoroutineUninterceptedOrReturn<Nothing > {
@@ -198,7 +189,7 @@ private fun createStackTrace(continuation: CoroutineStackFrame): ArrayDeque<Stac
198
189
}
199
190
200
191
internal fun StackTraceElement.isArtificial () = className.startsWith(ARTIFICIAL_FRAME_PACKAGE_NAME )
201
- private fun Array<StackTraceElement>.frameIndex (methodName : String ) = indexOfFirst { methodName == it.className }
192
+ private fun Array<StackTraceElement>.firstFrameIndex (methodName : String ) = indexOfFirst { methodName == it.className }
202
193
203
194
private fun StackTraceElement.elementWiseEquals (e : StackTraceElement ): Boolean {
204
195
/*
0 commit comments