Vanja's fix for Kotlin reflection in GraalVM

This commit is contained in:
pclaura 2022-03-08 16:14:24 +00:00 committed by lemjclarke
parent 880f7ae4ce
commit 12f512057f

View File

@ -5,6 +5,7 @@ import net.corda.core.internal.isConcreteClass
import net.corda.core.internal.kotlinObjectInstance import net.corda.core.internal.kotlinObjectInstance
import net.corda.core.serialization.ConstructorForDeserialization import net.corda.core.serialization.ConstructorForDeserialization
import net.corda.core.serialization.DeprecatedConstructorForDeserialization import net.corda.core.serialization.DeprecatedConstructorForDeserialization
import net.corda.core.utilities.SgxSupport
import net.corda.serialization.internal.NotSerializableDetailedException import net.corda.serialization.internal.NotSerializableDetailedException
import net.corda.serialization.internal.amqp.* import net.corda.serialization.internal.amqp.*
import net.corda.serialization.internal.model.LocalTypeInformation.Abstract import net.corda.serialization.internal.model.LocalTypeInformation.Abstract
@ -488,15 +489,17 @@ internal data class LocalTypeInformationBuilder(val lookup: LocalTypeLookup,
private fun Method.returnsNullable(): Boolean = try { private fun Method.returnsNullable(): Boolean = try {
val returnTypeString = this.declaringClass.kotlin.memberProperties.firstOrNull { val returnTypeString = this.declaringClass.kotlin.memberProperties.firstOrNull {
it.javaGetter == this it.javaGetter == this || run {
}?.returnType?.toString() ?: "?" val getterName = it.getter.name.replace("_", "")
(SgxSupport.isInsideEnclave && this.name == getterName.substringBefore("-").replace("<", "") + getterName.substringAfter("-")
.capitalize().replace(">", ""))
}
}
returnTypeString.endsWith('?') || returnTypeString.endsWith('!') returnTypeString?.returnType?.isMarkedNullable ?: true
} catch (e: KotlinReflectionInternalError) { } catch (e: KotlinReflectionInternalError) {
// This might happen for some types, e.g. kotlin.Throwable? - the root cause of the issue // This might happen for some types, e.g. kotlin.Throwable? - the root cause of the issue
// is: https://youtrack.jetbrains.com/issue/KT-13077 // is: https://youtrack.jetbrains.com/issue/KT-13077 // TODO: Revisit this when Kotlin issue is fixed.
// TODO: Revisit this when Kotlin issue is fixed.
true true
} }