From 2e4aaa761a8790598362e1ee91ce7fb13483cb10 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Thu, 24 Feb 2022 01:48:42 -0800 Subject: [PATCH] Validate that throwing tryCopy does not crash with an internal error (#3063) Motivated by #3031 --- .../StackTraceRecoveryCustomExceptionsTest.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryCustomExceptionsTest.kt b/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryCustomExceptionsTest.kt index dba738a8d3..d4e19040a5 100644 --- a/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryCustomExceptionsTest.kt +++ b/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryCustomExceptionsTest.kt @@ -124,4 +124,22 @@ class StackTraceRecoveryCustomExceptionsTest : TestBase() { assertTrue(ex is CopyableWithCustomMessage) assertEquals("Recovered: [OK]", ex.message) } + + @Test + fun testTryCopyThrows() = runTest { + class FailingException : Exception(), CopyableThrowable { + override fun createCopy(): FailingException? { + TODO("Not yet implemented") + } + } + + val e = FailingException() + val result = runCatching { + coroutineScope { + throw e + } + } + + assertSame(e, result.exceptionOrNull()) + } }