diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index 62caf1b1bdcef0e280619c53dc65f4dbfffcb294..19b8da7b045469a1ed014781990188816690bde8 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 0000000000000000000000000000000000000000..e4040a6379450f25e6d20e5b0e1eaa16020d2c9d --- /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 ab6117e266e866fe6860420d63027763c7242f8f..30da7cb5b090f610dbc8454489c4b20091b6faa0 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 45dd6ead83807de7b25f73e3dafbb02b49a29e9c..4d1bf16a7333eca970fd9f5aa3171b7176ce9520 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 dc27d309d4ab95b72535f5ffddce225e248ecf2b..b3410a183a7163091730853c51487616895438c8 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 a871e3205577700ff35f448bb096ee900f41fb00..cacf8578cc8a17a3de9c138b67ddc8b174e5a05e 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 7c698c4f2b1f9ba28cf2b90c46a8e69294785e2b..7d967e65165a05624b39d1fd47d68e7ae3f47b97 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 873fd445647c4cbd9c48b6bf1ac28f0d2ef0f275..652189b14074b87c61510d1a19fffb97b2c77fba 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 df65411e76cd6e090e2df263e4f3115596dce567..c32ab47be3f107aa80b5118fec909d71c2e320a7 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 78a9d14c7c2de3fb1faa085abcd0ceddc465e899..9f4f2382ea80b7c0f3d42a692742cc8b1d5b0d9b 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 5c8b47ed2339ece1a601cb5b4bf758f8186655e8..833fc2bdbd865c04eb0fd3005ef51951bed57252 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 ebb533c25f60e7b0f100d6111658bdeef1879330..77e9705472aef48ee7eb461ada13b4cecb0b7c6f 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 267ca7df9b54f64b2f384408e888134582c8a3b9..c746644064ed46578bc17e4b982f9e7a0989deb9 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 e88fb877e9d7195faff56deb5ee5fe3312b10755..ec6819ebe08f6e4a06832ae753a16236e460ae32 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 799b5e6ac4d6ba26cecbaa6ed0956ee764696ddb..3d6317f308dbec88bbf55e4bec0cb559a61c0e0c 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 c5ed215a3d54a415aa624ee5a98ce9aae8f2047a..28bb38501d27078164220ab7e7343ba0041a4246 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 cba1d45bb6bd99cef3ba4d2ff536f6f0e0a917a3..c5f978f949b516ea39d736aead349637d52afc6f 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 69b17b51ca902ec7cfea2aab9538e22e7984a1cd..aa52f8b1cd9a2aebdf6a694489eb035ab9d455d0 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 2f3a0c515e2e792e93c6ac0695d42877d823d3e9..df54af39bdce3258ff0320ba3728cc175151d4ef 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 c1bec7625d8a7e8f08fa484f8251ab1ba244b228..09a867e28f4fe0c02ef3253e6b15dc1c4d4ba1ac 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 9823690fb78e30fe18cdbfb9f4de4ae214c5ccbb..eb62da206ad4b0a853b83f31cc50299c4b8ca83c 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 a000a9823e858bc95ab12479e9af5f77095d2d43..2380393c339109e7c1b586007fd08c8de8f6f223 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