@@ -33,16 +33,16 @@ private val stackTraceRecoveryClassName = runCatching {
3333internal actual fun <E : Throwable > recoverStackTrace (exception : E ): E {
3434 if (! RECOVER_STACK_TRACES ) return exception
3535 // 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
3737 return copy.sanitizeStackTrace()
3838}
3939
4040private fun <E : Throwable > E.sanitizeStackTrace (): E {
4141 val stackTrace = stackTrace
4242 val size = stackTrace.size
43- val lastIntrinsic = stackTrace.frameIndex( stackTraceRecoveryClassName)
43+ val lastIntrinsic = stackTrace.indexOfLast { stackTraceRecoveryClassName == it.className }
4444 val startIndex = lastIntrinsic + 1
45- val endIndex = stackTrace.frameIndex (baseContinuationImplClassName)
45+ val endIndex = stackTrace.firstFrameIndex (baseContinuationImplClassName)
4646 val adjustment = if (endIndex == - 1 ) 0 else size - endIndex
4747 val trace = Array (size - lastIntrinsic - adjustment) {
4848 if (it == 0 ) {
@@ -70,7 +70,7 @@ private fun <E : Throwable> recoverFromStackFrame(exception: E, continuation: Co
7070 val (cause, recoveredStacktrace) = exception.causeAndStacktrace()
7171
7272 // 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
7474 // Update stacktrace
7575 val stacktrace = createStackTrace(continuation)
7676 if (stacktrace.isEmpty()) return exception
@@ -82,14 +82,6 @@ private fun <E : Throwable> recoverFromStackFrame(exception: E, continuation: Co
8282 return createFinalException(cause, newException, stacktrace)
8383}
8484
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-
9385/*
9486 * Here we partially copy original exception stackTrace to make current one much prettier.
9587 * E.g. for
@@ -109,7 +101,7 @@ private fun <E : Throwable> tryCopyAndVerify(exception: E): E? {
109101private fun <E : Throwable > createFinalException (cause : E , result : E , resultStackTrace : ArrayDeque <StackTraceElement >): E {
110102 resultStackTrace.addFirst(ARTIFICIAL_FRAME )
111103 val causeTrace = cause.stackTrace
112- val size = causeTrace.frameIndex (baseContinuationImplClassName)
104+ val size = causeTrace.firstFrameIndex (baseContinuationImplClassName)
113105 if (size == - 1 ) {
114106 result.stackTrace = resultStackTrace.toTypedArray()
115107 return result
@@ -157,7 +149,6 @@ private fun mergeRecoveredTraces(recoveredStacktrace: Array<StackTraceElement>,
157149 }
158150}
159151
160- @Suppress(" NOTHING_TO_INLINE" )
161152internal actual suspend inline fun recoverAndThrow (exception : Throwable ): Nothing {
162153 if (! RECOVER_STACK_TRACES ) throw exception
163154 suspendCoroutineUninterceptedOrReturn<Nothing > {
@@ -198,7 +189,7 @@ private fun createStackTrace(continuation: CoroutineStackFrame): ArrayDeque<Stac
198189}
199190
200191internal 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 }
202193
203194private fun StackTraceElement.elementWiseEquals (e : StackTraceElement ): Boolean {
204195 /*
0 commit comments