diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index 62caf1b1bdc..19b8da7b045 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -1274,8 +1274,10 @@ public final class String : kotlin.Comparable, kotlin.CharSequenc public open class Throwable { /*primary*/ public constructor Throwable(/*0*/ message: kotlin.String? = ..., /*1*/ cause: kotlin.Throwable? = ...) - public final fun getCause(): kotlin.Throwable? - public final fun getMessage(): kotlin.String? + public final val cause: kotlin.Throwable? + public final fun (): kotlin.Throwable? + public final val message: kotlin.String? + public final fun (): kotlin.String? public final fun printStackTrace(): kotlin.Unit } diff --git a/compiler/testData/codegen/box/builtinsProperties/throwable.kt b/compiler/testData/codegen/box/builtinsProperties/throwable.kt new file mode 100644 index 00000000000..e4040a63794 --- /dev/null +++ b/compiler/testData/codegen/box/builtinsProperties/throwable.kt @@ -0,0 +1,10 @@ +fun box(): String { + try { + throw Throwable("OK", null) + } catch (t: Throwable) { + if (t.cause != null) return "fail 1" + return t.message!! + } + + return "fail 2" +} diff --git a/compiler/testData/codegen/box/classes/exceptionConstructor.kt b/compiler/testData/codegen/box/classes/exceptionConstructor.kt index ab6117e266e..30da7cb5b09 100644 --- a/compiler/testData/codegen/box/classes/exceptionConstructor.kt +++ b/compiler/testData/codegen/box/classes/exceptionConstructor.kt @@ -3,5 +3,5 @@ class GameError(msg: String): Exception(msg) { fun box(): String { val e = GameError("foo") - return if (e.getMessage() == "foo") "OK" else "fail" + return if (e.message == "foo") "OK" else "fail" } diff --git a/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/multipleCatchBlocks.kt b/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/multipleCatchBlocks.kt index 45dd6ead838..4d1bf16a733 100644 --- a/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/multipleCatchBlocks.kt +++ b/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/multipleCatchBlocks.kt @@ -13,7 +13,7 @@ fun box(): String = "e2" } catch (e3: Exception3) { - e3.getMessage() + e3.message } catch (e: Exception) { "e" diff --git a/compiler/testData/codegen/controlStructures/tryCatch.kt b/compiler/testData/codegen/controlStructures/tryCatch.kt index dc27d309d4a..b3410a183a7 100644 --- a/compiler/testData/codegen/controlStructures/tryCatch.kt +++ b/compiler/testData/codegen/controlStructures/tryCatch.kt @@ -4,6 +4,6 @@ fun foo(s: String): String? { return "no message"; } catch(e: NumberFormatException) { - return e.getMessage(); // Work around an overload-resolution bug + return e.message // Work around an overload-resolution bug } } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.txt index a871e320557..cacf8578cc8 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.txt @@ -2,15 +2,15 @@ package test public final class E1 : java.lang.Exception { public constructor E1() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.txt index 7c698c4f2b1..7d967e65165 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.txt @@ -2,15 +2,15 @@ package test public final class E1 : java.lang.Exception { public constructor E1() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.txt index 873fd445647..652189b1407 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.txt @@ -4,8 +4,8 @@ package test public final class E1 : java.lang.Exception { public constructor E1() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.txt index df65411e76c..c32ab47be3f 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.txt @@ -2,15 +2,15 @@ package test public final class E1 : java.lang.Exception { public constructor E1() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.txt index 78a9d14c7c2..9f4f2382ea8 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.txt @@ -11,8 +11,8 @@ public final class Derived : test.Base { public final class E1 : java.lang.Exception { public constructor E1() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.txt index 5c8b47ed233..833fc2bdbd8 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.txt @@ -6,15 +6,15 @@ public fun two(): kotlin.Unit public final class E1 : java.lang.Exception { public constructor E1() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.txt index ebb533c25f6..77e9705472a 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.txt @@ -2,15 +2,15 @@ package test public final class E1 : java.lang.Exception { public constructor E1() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() - public final /*fake_override*/ fun getCause(): kotlin.Throwable? - public final /*fake_override*/ fun getMessage(): kotlin.String? + public final /*fake_override*/ val cause: kotlin.Throwable? + public final /*fake_override*/ val message: kotlin.String? public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } diff --git a/compiler/testData/diagnostics/tests/ResolveToJava.kt b/compiler/testData/diagnostics/tests/ResolveToJava.kt index 267ca7df9b5..c746644064e 100644 --- a/compiler/testData/diagnostics/tests/ResolveToJava.kt +++ b/compiler/testData/diagnostics/tests/ResolveToJava.kt @@ -36,7 +36,7 @@ fun test(l : java.util // ... } catch(e: Exception) { - System.out.println(e.getMessage()) + System.out.println(e.message) } PrintStream("sdf") diff --git a/compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt b/compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt index e88fb877e9d..ec6819ebe08 100644 --- a/compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt +++ b/compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt @@ -60,6 +60,6 @@ fun main(args: Array) { System.out.println("You won!"); } catch(e: Throwable) { - System.out.println(e.getMessage()) + System.out.println(e.message) } } diff --git a/compiler/testData/diagnostics/tests/regressions/kt498.txt b/compiler/testData/diagnostics/tests/regressions/kt498.txt index 799b5e6ac4d..3d6317f308d 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt498.txt +++ b/compiler/testData/diagnostics/tests/regressions/kt498.txt @@ -4,9 +4,9 @@ public fun T.getJavaClass(): java.lang.Class public final class IdUnavailableException : java.lang.Exception { public constructor IdUnavailableException() + public final override /*1*/ /*fake_override*/ val cause: kotlin.Throwable? + public final override /*1*/ /*fake_override*/ val message: kotlin.String? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public final override /*1*/ /*fake_override*/ fun getCause(): kotlin.Throwable? - public final override /*1*/ /*fake_override*/ fun getMessage(): kotlin.String? public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public final override /*1*/ /*fake_override*/ fun printStackTrace(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index c5ed215a3d5..28bb38501d2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -921,6 +921,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinsProperties/maps.kt"); doTest(fileName); } + + @TestMetadata("throwable.kt") + public void testThrowable() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinsProperties/throwable.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/casts") diff --git a/core/builtins/native/kotlin/Throwable.kt b/core/builtins/native/kotlin/Throwable.kt index cba1d45bb6b..c5f978f949b 100644 --- a/core/builtins/native/kotlin/Throwable.kt +++ b/core/builtins/native/kotlin/Throwable.kt @@ -22,17 +22,7 @@ package kotlin * @param message the detail message string. * @param cause the cause of this throwable. */ -public open class Throwable(message: String? = null, cause: Throwable? = null) { - /** - * Returns the detail message of this throwable. - */ - public fun getMessage(): String? - - /** - * Returns the cause of this throwable. - */ - public fun getCause(): Throwable? - +public open class Throwable(val message: String? = null, val cause: Throwable? = null) { /** * Prints the stack trace of this throwable to the standard output. */ diff --git a/idea/testData/checker/ResolveToJava.kt b/idea/testData/checker/ResolveToJava.kt index 69b17b51ca9..aa52f8b1cd9 100644 --- a/idea/testData/checker/ResolveToJava.kt +++ b/idea/testData/checker/ResolveToJava.kt @@ -35,7 +35,7 @@ fun test(l : List) { // ... } catch(e: Exception) { - System.out.println(e.getMessage()) + System.out.println(e.message) } PrintStream("sdf") diff --git a/idea/testData/checker/regression/DoubleDefine.kt b/idea/testData/checker/regression/DoubleDefine.kt index 2f3a0c515e2..df54af39bdc 100644 --- a/idea/testData/checker/regression/DoubleDefine.kt +++ b/idea/testData/checker/regression/DoubleDefine.kt @@ -60,6 +60,6 @@ fun main(args: Array) { System.out.println("You won!"); } catch(e: Throwable) { - System.out.println(e.getMessage()) + System.out.println(e.message) } } diff --git a/js/js.translator/testData/regression/cases/kt2470.kt b/js/js.translator/testData/regression/cases/kt2470.kt index c1bec7625d8..09a867e28f4 100644 --- a/js/js.translator/testData/regression/cases/kt2470.kt +++ b/js/js.translator/testData/regression/cases/kt2470.kt @@ -2,8 +2,6 @@ package foo -@native val Exception.message: String get() = noImpl - public fun failsWith(block: () -> Any): T { try { block() @@ -20,5 +18,5 @@ fun box(): String { throw Exception("OK") } - return a.message + return a.message!! } diff --git a/js/js.translator/testData/standardClasses/cases/arrayFactoryMethods.kt b/js/js.translator/testData/standardClasses/cases/arrayFactoryMethods.kt index 9823690fb78..eb62da206ad 100644 --- a/js/js.translator/testData/standardClasses/cases/arrayFactoryMethods.kt +++ b/js/js.translator/testData/standardClasses/cases/arrayFactoryMethods.kt @@ -1,6 +1,6 @@ package foo -class Fail(val message: String) : Exception(message) +class Fail(message: String) : Exception(message) fun test(testName: String, actual: Any, expectedAsString: String) { val expected = eval("[$expectedAsString]") @@ -20,7 +20,7 @@ fun box(): String { test("doubleArrayOf", doubleArrayOf(0.0, 1.1, 2.2, 3.3, 4.4), "0.0, 1.1, 2.2, 3.3, 4.4") } catch (e: Fail) { - return e.message + return e.message!! } return "OK" diff --git a/libraries/stdlib/src/kotlin/collections/DeprecatedBuiltins.kt b/libraries/stdlib/src/kotlin/collections/DeprecatedBuiltins.kt index a000a9823e8..2380393c339 100644 --- a/libraries/stdlib/src/kotlin/collections/DeprecatedBuiltins.kt +++ b/libraries/stdlib/src/kotlin/collections/DeprecatedBuiltins.kt @@ -78,3 +78,9 @@ public inline fun Map.values(): Collection = values @kotlin.jvm.JvmName("mutableValues") @Deprecated("Use property 'values' instead", ReplaceWith("this.values")) public inline fun MutableMap.values(): MutableCollection = values + +@Deprecated("Use property 'message' instead", ReplaceWith("this.message")) +public inline fun Throwable.getMessage(): String? = message + +@Deprecated("Use property 'cause' instead", ReplaceWith("this.cause")) +public inline fun Throwable.getCause(): Throwable? = cause