Add null checks in constructors taking value class types
^KT-53492: Fixed
This commit is contained in:
committed by
teamcity
parent
cd6e865fb3
commit
50e92d2238
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
import java.lang.NullPointerException
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class IC(val str: String)
|
||||
|
||||
class A(val a: IC, val x : String) {
|
||||
fun foo() = "$a$x"
|
||||
|
||||
private constructor(x: IC) : this(IC(""), "")
|
||||
}
|
||||
|
||||
inline fun assertThrowsExpectedException(block: () -> Unit): Boolean {
|
||||
try {
|
||||
block()
|
||||
} catch (t: Throwable) {
|
||||
return t is InvocationTargetException && t.targetException is NullPointerException
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!assertThrowsExpectedException { ::A.call(null, "").foo() }) return "Fail 1"
|
||||
if (!assertThrowsExpectedException { ::A.call(IC(""), null).foo() }) return "Fail 2"
|
||||
val privateConstructor = A::class.constructors.single { it.parameters.size == 1 }
|
||||
privateConstructor.also { it.isAccessible = true }.call(null).foo()
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user