Fix codegen & bytecode tests after unifying exceptions in JVM backend

See KT-22275 for details
This commit is contained in:
Mikhail Zarechenskiy
2020-01-20 13:51:11 +03:00
parent 1ed7e33f42
commit 5c5635ce20
34 changed files with 55 additions and 55 deletions
@@ -75,7 +75,7 @@ fun box(): String {
// and returning defaultValue if null was received seems incorrect here // and returning defaultValue if null was received seems incorrect here
mm.getOrDefault("abc", null) mm.getOrDefault("abc", null)
return "fail 7" return "fail 7"
} catch (e: java.lang.IllegalArgumentException) { } catch (e: java.lang.NullPointerException) {
// Parameter specified as non-null is null // Parameter specified as non-null is null
} }
+1 -1
View File
@@ -19,7 +19,7 @@ fun box(): String {
try { try {
test3<Int>() test3<Int>()
} }
catch(e: TypeCastException) { catch(e: NullPointerException) {
result3 = "OK" result3 = "OK"
} }
if (result3 != "OK") return "fail: test3" if (result3 != "OK") return "fail: test3"
+2 -2
View File
@@ -35,7 +35,7 @@ fun box(): String {
suspendHere() suspendHere()
} }
return "fail 1" return "fail 1"
} catch (e: kotlin.KotlinNullPointerException) { } catch (e: NullPointerException) {
} }
try { try {
@@ -54,7 +54,7 @@ fun box(): String {
result = "fail 5" result = "fail 5"
} }
return "fail 6" return "fail 6"
} catch (e: kotlin.KotlinNullPointerException) { } catch (e: NullPointerException) {
} }
try { try {
@@ -13,7 +13,7 @@ fun box(): String {
try { try {
val b: String = a[0] val b: String = a[0]
return "Fail: an exception should be thrown" return "Fail: an exception should be thrown"
} catch (e: IllegalStateException) { } catch (e: NullPointerException) {
val st = (e as java.lang.Throwable).getStackTrace() val st = (e as java.lang.Throwable).getStackTrace()
if (st.size < 5) { if (st.size < 5) {
return "Fail: very small stack trace, should at least have current function and JUnit reflective calls: ${Arrays.toString(st)}" return "Fail: very small stack trace, should at least have current function and JUnit reflective calls: ${Arrays.toString(st)}"
@@ -15,7 +15,7 @@ private operator fun J.component2() = 2
fun use(x: Any) {} fun use(x: Any) {}
fun box(): String { fun box(): String {
assertFailsWith<IllegalArgumentException> { assertFailsWith<NullPointerException> {
val (a, b) = J.j() val (a, b) = J.j()
} }
if (!component1Evaluated) return "component1 should be evaluated" if (!component1Evaluated) return "component1 should be evaluated"
@@ -6,7 +6,7 @@ fun f(x: String) = "Fail 1"
fun box(): String { fun box(): String {
return try { return try {
f(J().s()) f(J().s())
} catch (e: IllegalStateException) { } catch (e: NullPointerException) {
if (e.message == "J().s() must not be null") if (e.message == "J().s() must not be null")
"OK" "OK"
else else
@@ -8,11 +8,11 @@ public class Test {
try { try {
ExtensionKt.foo(null); ExtensionKt.foo(null);
} }
catch (IllegalArgumentException e) { catch (NullPointerException e) {
try { try {
ExtensionKt.getBar(null); ExtensionKt.getBar(null);
} }
catch (IllegalArgumentException f) { catch (NullPointerException f) {
return "OK"; return "OK";
} }
} }
@@ -20,18 +20,18 @@ public class Test {
args[i] = null; args[i] = null;
try { try {
f.invoke(args); f.invoke(args);
} catch (IllegalArgumentException e) { } catch (NullPointerException e) {
// OK // OK
continue; continue;
} catch (Throwable e) { } catch (Throwable e) {
throw new AssertionError( throw new AssertionError(
"Incorrect exception (IllegalArgumentException expected): " + e.getClass().getName() + ", parameter index = " + i, "Incorrect exception (NullPointerException expected): " + e.getClass().getName() + ", parameter index = " + i,
e e
); );
} finally { } finally {
args[i] = o; args[i] = o;
} }
throw new AssertionError("IllegalArgumentException expected, but nothing was thrown, parameter index = " + i); throw new AssertionError("NullPointerException expected, but nothing was thrown, parameter index = " + i);
} }
} }
} }
@@ -8,7 +8,7 @@ import kotlin.test.*
operator fun A.inc() = A() operator fun A.inc() = A()
fun box(): String { fun box(): String {
assertFailsWith<IllegalArgumentException> { assertFailsWith<NullPointerException> {
var aNull = A.n() var aNull = A.n()
aNull++ aNull++
} }
@@ -8,7 +8,7 @@ import kotlin.test.*
private operator fun A.inc() = A() private operator fun A.inc() = A()
fun box(): String { fun box(): String {
assertFailsWith<IllegalArgumentException> { assertFailsWith<NullPointerException> {
var aNull = A.n() var aNull = A.n()
aNull++ aNull++
} }
@@ -16,7 +16,7 @@ public class F {
inline fun <T, U> expectAssertion(f: () -> (T) -> U): Unit? { inline fun <T, U> expectAssertion(f: () -> (T) -> U): Unit? {
try { try {
F.passNull(f()) F.passNull(f())
} catch (e: IllegalArgumentException) { } catch (e: NullPointerException) {
return Unit return Unit
} }
return null return null
@@ -10,7 +10,7 @@ class C : I
fun box() = try { fun box() = try {
B.f() B.f()
"FAIL" "FAIL"
} catch (e: IllegalArgumentException) { } catch (e: NullPointerException) {
"OK" "OK"
} }
@@ -8,7 +8,7 @@ import kotlin.test.*
fun String.extension() {} fun String.extension() {}
fun box(): String { fun box(): String {
assertFailsWith<IllegalStateException> { J.s().extension() } assertFailsWith<NullPointerException> { J.s().extension() }
return "OK" return "OK"
} }
@@ -8,7 +8,7 @@ import kotlin.test.*
inline fun String.extension() {} inline fun String.extension() {}
fun box(): String { fun box(): String {
assertFailsWith<IllegalStateException> { assertFailsWith<NullPointerException> {
J.s().extension() J.s().extension()
} }
return "OK" return "OK"
@@ -11,7 +11,7 @@ class C {
} }
fun box(): String { fun box(): String {
assertFailsWith<IllegalStateException> { C().test() } assertFailsWith<NullPointerException> { C().test() }
return "OK" return "OK"
} }
@@ -11,7 +11,7 @@ class C {
} }
fun box(): String { fun box(): String {
assertFailsWith<IllegalStateException> { assertFailsWith<NullPointerException> {
C().test() C().test()
} }
return "OK" return "OK"
@@ -17,11 +17,11 @@ fun box(): String {
try { try {
Test.callFoo() Test.callFoo()
return "Fail 1" return "Fail 1"
} catch (e : IllegalArgumentException) { } catch (e: NullPointerException) {
if (e.message != "Parameter specified as non-null is null: method A.foo, parameter s") { if (e.message != "Parameter specified as non-null is null: method A.foo, parameter s") {
return "Fail 2 (message: ${e.message})" return "Fail 2 (message: ${e.message})"
} }
} catch (e : Throwable) { } catch (e: Throwable) {
return "Fail 3 (exception class: ${e::class.simpleName})" return "Fail 3 (exception class: ${e::class.simpleName})"
} }
return "OK" return "OK"
@@ -6,7 +6,7 @@ fun f(x: String) = "Fail 1"
fun box(): String { fun box(): String {
return try { return try {
f(J.s()) f(J.s())
} catch (e: IllegalStateException) { } catch (e: NullPointerException) {
if (e.message == "J.s() must not be null" || e.message == "s() must not be null") if (e.message == "J.s() must not be null" || e.message == "s() must not be null")
"OK" "OK"
else else
@@ -9,7 +9,7 @@ import kotlin.test.*
operator fun A.inc() = A() operator fun A.inc() = A()
fun box(): String { fun box(): String {
assertFailsWith<IllegalArgumentException> { assertFailsWith<NullPointerException> {
var aNull = A.n() var aNull = A.n()
aNull++ aNull++
} }
@@ -8,7 +8,7 @@ import kotlin.test.*
fun String.extension() {} fun String.extension() {}
fun box(): String { fun box(): String {
assertFailsWith<IllegalArgumentException> { J.s().extension() } assertFailsWith<NullPointerException> { J.s().extension() }
return "OK" return "OK"
} }
@@ -12,7 +12,7 @@ fun box(): String {
val a: Any? = null val a: Any? = null
a as Array<String> a as Array<String>
} }
catch (e: TypeCastException) { catch (e: NullPointerException) {
if (e.message != "null cannot be cast to non-null type kotlin.Array<kotlin.String>") { if (e.message != "null cannot be cast to non-null type kotlin.Array<kotlin.String>") {
return "Fail 1: $e" return "Fail 1: $e"
} }
@@ -22,7 +22,7 @@ fun box(): String {
val x: String? = null val x: String? = null
x as String x as String
} }
catch (e: TypeCastException) { catch (e: NullPointerException) {
if (e.message != "null cannot be cast to non-null type kotlin.String") { if (e.message != "null cannot be cast to non-null type kotlin.String") {
return "Fail 2: $e" return "Fail 2: $e"
} }
@@ -30,7 +30,7 @@ fun box(): String {
try { try {
if (jClass.minus0().compareTo(jClass.null0()) != -2) return "fail 3" if (jClass.minus0().compareTo(jClass.null0()) != -2) return "fail 3"
return "fail: exception expected"; return "fail: exception expected";
} catch (e: IllegalStateException) { } catch (e: NullPointerException) {
} }
+1 -1
View File
@@ -31,7 +31,7 @@ fun box(): String {
} }
}) })
}.run() }.run()
} catch (e: IllegalArgumentException) { } catch (e: NullPointerException) {
return "OK" return "OK"
} }
@@ -1,15 +1,15 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS // KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS
// FILE: callAssertions.kt // FILE: callAssertions.kt
class AssertionChecker(val illegalStateExpected: Boolean) { class AssertionChecker(val nullPointerExceptionExpected: Boolean) {
operator fun invoke(name: String, f: () -> Any) { operator fun invoke(name: String, f: () -> Any) {
try { try {
f() f()
} catch (e: IllegalStateException) { } catch (e: NullPointerException) {
if (!illegalStateExpected) throw AssertionError("Unexpected IllegalStateException on calling $name") if (!nullPointerExceptionExpected) throw AssertionError("Unexpected NullPointerException on calling $name")
return return
} }
if (illegalStateExpected) throw AssertionError("IllegalStateException expected on calling $name") if (nullPointerExceptionExpected) throw AssertionError("NullPointerException expected on calling $name")
} }
} }
@@ -15,7 +15,7 @@ fun box(): String {
DelegateFrom().foo() DelegateFrom().foo()
return "Fail: should have been an exception" return "Fail: should have been an exception"
} }
catch(e: IllegalStateException) { catch(e: NullPointerException) {
return "OK" return "OK"
} }
} }
@@ -11,10 +11,10 @@ public abstract class C<Type> {
public static void runTest(C a) { public static void runTest(C a) {
try { try {
a.doTest(null); a.doTest(null);
} catch (IllegalArgumentException e) { } catch (NullPointerException e) {
return; return;
} }
throw new AssertionError("Fail: IllegalArgumentException expected"); throw new AssertionError("Fail: NullPointerException expected");
} }
} }
@@ -19,13 +19,13 @@ fun box(): String {
foo(baz() ?: RightElvisOperand.foo()) foo(baz() ?: RightElvisOperand.foo())
return "Fail: should have been an exception in `foo(baz() ?: RightElvisOperand.foo())`" return "Fail: should have been an exception in `foo(baz() ?: RightElvisOperand.foo())`"
} }
catch(e: IllegalStateException) {} catch(e: NullPointerException) {}
try { try {
bar() bar()
return "Fail: should have been an exception in `bar()`" return "Fail: should have been an exception in `bar()`"
} }
catch(e: IllegalStateException) { catch(e: NullPointerException) {
return "OK" return "OK"
} }
} }
@@ -19,7 +19,7 @@ fun box(): String {
try { try {
test(JavaClass().test()) test(JavaClass().test())
} }
catch (e: IllegalStateException) { catch (e: NullPointerException) {
return "OK" return "OK"
} }
return "fail" return "fail"
@@ -14,8 +14,8 @@ fun asNullablePrimitive(c: AsNonNullPrimitive?) {}
fun asNullableReference(c: AsNonNullReference?) {} fun asNullableReference(c: AsNonNullReference?) {}
// JVM_TEMPLATES // JVM_TEMPLATES
// 6 checkParameterIsNotNull // 0 checkParameterIsNotNull
// 0 checkNotNullParameter // 6 checkNotNullParameter
// JVM_IR_TEMPLATES // JVM_IR_TEMPLATES
// 4 checkParameterIsNotNull // 4 checkParameterIsNotNull
@@ -8,7 +8,7 @@ fun foo(): Any {
fun bar(a: ArrayList<String>) { fun bar(a: ArrayList<String>) {
} }
// 1 checkExpressionValueIsNotNull // 0 checkExpressionValueIsNotNull
// 0 checkNotNullExpressionValue // 1 checkNotNullExpressionValue
// 1 checkParameterIsNotNull // 0 checkParameterIsNotNull
// 0 checkNotNullParameter // 1 checkNotNullParameter
@@ -6,5 +6,5 @@ public fun <R : Any> foo(x: MutableCollection<in R>, block: java.util.AbstractLi
x.add(block.get(0)) x.add(block.get(0))
} }
// 1 checkExpressionValueIsNotNull // 0 checkExpressionValueIsNotNull
// 0 checkNotNullExpressionValue // 1 checkNotNullExpressionValue
@@ -1,4 +1,4 @@
fun <T : Any> foo(t: T) = t fun <T : Any> foo(t: T) = t
// 1 checkParameterIsNotNull // 0 checkParameterIsNotNull
// 0 checkNotNullParameter // 1 checkNotNullParameter
@@ -32,7 +32,7 @@ internal fun bar(a: A<String, Int>, b: B<String>, c: C) {
} }
// @JavaMultipleSubstitutionsKt.class // @JavaMultipleSubstitutionsKt.class
// 3 checkExpressionValueIsNotNull // 0 checkExpressionValueIsNotNull
// 0 checkNotNullExpressionValue // 3 checkNotNullExpressionValue
// 3 checkParameterIsNotNull // 0 checkParameterIsNotNull
// 0 checkNotNullParameter // 3 checkNotNullParameter
@@ -21,5 +21,5 @@ fun test() {
// @KKt.class: // @KKt.class:
// 1 LDC "a" // 1 LDC "a"
// 1 checkExpressionValueIsNotNull // 0 checkExpressionValueIsNotNull
// 0 checkNotNullExpressionValue // 1 checkNotNullExpressionValue