diff --git a/libraries/stdlib/jdk7/src/kotlin/internal/jdk7/JDK7PlatformImplementations.kt b/libraries/stdlib/jdk7/src/kotlin/internal/jdk7/JDK7PlatformImplementations.kt index 6eaeff35ae3..b3269e7b93d 100644 --- a/libraries/stdlib/jdk7/src/kotlin/internal/jdk7/JDK7PlatformImplementations.kt +++ b/libraries/stdlib/jdk7/src/kotlin/internal/jdk7/JDK7PlatformImplementations.kt @@ -10,7 +10,8 @@ import kotlin.internal.PlatformImplementations internal open class JDK7PlatformImplementations : PlatformImplementations() { - override fun addSuppressed(cause: Throwable, exception: Throwable) = cause.addSuppressed(exception) + @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") + override fun addSuppressed(cause: Throwable, exception: Throwable) = (cause as java.lang.Throwable).addSuppressed(exception) override fun getSuppressed(exception: Throwable): List = exception.suppressed.asList() } diff --git a/libraries/stdlib/jvm/src/kotlin/util/Exceptions.kt b/libraries/stdlib/jvm/src/kotlin/util/Exceptions.kt index a8319c6b8d8..5e12bdcb460 100644 --- a/libraries/stdlib/jvm/src/kotlin/util/Exceptions.kt +++ b/libraries/stdlib/jvm/src/kotlin/util/Exceptions.kt @@ -65,6 +65,7 @@ public actual fun Throwable.stackTraceToString(): String { * suppressed in order to deliver this exception. */ @SinceKotlin("1.1") +@kotlin.internal.HidesMembers public actual fun Throwable.addSuppressed(exception: Throwable) { if (this !== exception) IMPLEMENTATIONS.addSuppressed(this, exception) diff --git a/libraries/stdlib/jvm/test/ExceptionJVMTest.kt b/libraries/stdlib/jvm/test/ExceptionJVMTest.kt index 469b2c2c6cd..84e134a49f4 100644 --- a/libraries/stdlib/jvm/test/ExceptionJVMTest.kt +++ b/libraries/stdlib/jvm/test/ExceptionJVMTest.kt @@ -81,6 +81,11 @@ class ExceptionJVMTest { e1.addSuppressed(e2) } + @Test fun addSuppressedSelfDoesNotThrow() { + val e1 = Throwable() + e1.addSuppressed(e1) // should not throw + } + @Test fun circularCauseStackTrace() { val e1 = Exception("cause") val e2 = Error("induced", e1)