diff --git a/libraries/stdlib/common/src/kotlin/ExceptionsH.kt b/libraries/stdlib/common/src/kotlin/ExceptionsH.kt index 9132d5b622e..fc29fce07c2 100644 --- a/libraries/stdlib/common/src/kotlin/ExceptionsH.kt +++ b/libraries/stdlib/common/src/kotlin/ExceptionsH.kt @@ -128,7 +128,8 @@ internal class KotlinNothingValueException : RuntimeException { * - the detailed description of each throwable in the [Throwable.cause] chain. */ @SinceKotlin("1.4") -public expect fun Throwable.toStringWithTrace(): String +public expect fun Throwable.stackTraceToString(): String + /** * When supported by the platform, adds the specified exception to the list of exceptions that were * suppressed in order to deliver this exception. diff --git a/libraries/stdlib/js/src/kotlin/throwableExtensions.kt b/libraries/stdlib/js/src/kotlin/throwableExtensions.kt index 958875b6e38..e176bb1595e 100644 --- a/libraries/stdlib/js/src/kotlin/throwableExtensions.kt +++ b/libraries/stdlib/js/src/kotlin/throwableExtensions.kt @@ -15,7 +15,7 @@ package kotlin * - the detailed description of each throwable in the [Throwable.cause] chain. */ @SinceKotlin("1.4") -public actual fun Throwable.toStringWithTrace(): String = ExceptionTraceBuilder().buildFor(this) +public actual fun Throwable.stackTraceToString(): String = ExceptionTraceBuilder().buildFor(this) /** * Adds the specified exception to the list of exceptions that were diff --git a/libraries/stdlib/jvm/src/kotlin/util/Exceptions.kt b/libraries/stdlib/jvm/src/kotlin/util/Exceptions.kt index 21fb871312c..e37e4c04143 100644 --- a/libraries/stdlib/jvm/src/kotlin/util/Exceptions.kt +++ b/libraries/stdlib/jvm/src/kotlin/util/Exceptions.kt @@ -14,21 +14,21 @@ import java.io.StringWriter import kotlin.internal.* /** - * Prints the [detailed description][Throwable.toStringWithTrace] of this throwable to the standard error output. + * Prints the [detailed description][Throwable.stackTraceToString] of this throwable to the standard error output. */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available @kotlin.internal.InlineOnly public inline fun Throwable.printStackTrace(): Unit = (this as java.lang.Throwable).printStackTrace() /** - * Prints the [detailed description][Throwable.toStringWithTrace] of this throwable to the specified [writer]. + * Prints the [detailed description][Throwable.stackTraceToString] of this throwable to the specified [writer]. */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available @kotlin.internal.InlineOnly public inline fun Throwable.printStackTrace(writer: PrintWriter): Unit = (this as java.lang.Throwable).printStackTrace(writer) /** - * Prints the [detailed description][Throwable.toStringWithTrace] of this throwable to the specified [stream]. + * Prints the [detailed description][Throwable.stackTraceToString] of this throwable to the specified [stream]. */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // to be used when no member available @kotlin.internal.InlineOnly @@ -52,7 +52,7 @@ public val Throwable.stackTrace: Array * - the detailed description of each throwable in the [Throwable.cause] chain. */ @SinceKotlin("1.4") -public actual fun Throwable.toStringWithTrace(): String { +public actual fun Throwable.stackTraceToString(): String { val sw = StringWriter() val pw = PrintWriter(sw) printStackTrace(pw) diff --git a/libraries/stdlib/jvm/test/ExceptionJVMTest.kt b/libraries/stdlib/jvm/test/ExceptionJVMTest.kt index 0ae48e92145..469b2c2c6cd 100644 --- a/libraries/stdlib/jvm/test/ExceptionJVMTest.kt +++ b/libraries/stdlib/jvm/test/ExceptionJVMTest.kt @@ -53,7 +53,7 @@ class ExceptionJVMTest { } fun assertToStringWithTrace(t: Throwable) { - val content = t.toStringWithTrace() + val content = t.stackTraceToString() comparePrintedThrowableResult(t, content) } @@ -88,7 +88,7 @@ class ExceptionJVMTest { assertSame(e1, e2.cause) assertSame(e2, e1.cause) testOnJvm7AndAbove { - val trace = e2.toStringWithTrace() + val trace = e2.stackTraceToString() assertTrue("CIRCULAR REFERENCE" in trace, trace) } } diff --git a/libraries/stdlib/test/ExceptionTest.kt b/libraries/stdlib/test/ExceptionTest.kt index f69ddbdb3bb..17230799942 100644 --- a/libraries/stdlib/test/ExceptionTest.kt +++ b/libraries/stdlib/test/ExceptionTest.kt @@ -109,7 +109,7 @@ class ExceptionTest { e.apply { addSuppressed(suppressedError(2)) } } - val topLevelTrace = e.toStringWithTrace() + val topLevelTrace = e.stackTraceToString() fun assertInTrace(value: Any) { if (value.toString() !in topLevelTrace) { fail("Expected top level trace: $topLevelTrace\n\nto contain: $value") @@ -153,7 +153,7 @@ class ExceptionTest { e3.addSuppressed(e1) e2.addSuppressed(e1) - val topLevelTrace = e1.toStringWithTrace() + val topLevelTrace = e1.stackTraceToString() fun assertAppearsInTrace(value: Any, count: Int) { if (Regex.fromLiteral(value.toString()).findAll(topLevelTrace).count() != count) { fail("Expected to find $value $count times in $topLevelTrace") diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt index f01de1ccd92..dc40d98cb2e 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt @@ -22,7 +22,7 @@ public final class kotlin/ExceptionsKt { public static final fun addSuppressed (Ljava/lang/Throwable;Ljava/lang/Throwable;)V public static final fun getStackTrace (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement; public static final fun getSuppressedExceptions (Ljava/lang/Throwable;)Ljava/util/List; - public static final fun toStringWithTrace (Ljava/lang/Throwable;)Ljava/lang/String; + public static final fun stackTraceToString (Ljava/lang/Throwable;)Ljava/lang/String; } public abstract interface annotation class kotlin/Experimental : java/lang/annotation/Annotation {