【发布时间】:2017-12-29 10:29:58
【问题描述】:
kotlin.reflect.jvm.internal.KotlinReflectionInternalError: 内省局部函数、lambda、匿名函数和局部函数 Kotlin 反射尚不完全支持变量
此异常来自数据类的toString()。
数据类包含一个 lambda。
我无法在我的环境中重现它。
我是否需要覆盖 toString() 以排除 lambda?或者数据类中根本不允许使用 lambda?
data class PersistJob(
private val id: Int,
private val delay: Long = 10_000L,
private val maxDelay: Long = 60_000L,
private val iteration: Int = 0,
private val block: suspend (Int) -> Boolean) {
fun getDelay() = minOf(delay, maxDelay)
fun withDelayIncreased() = copy(
delay = minOf(delay * 2, maxDelay),
iteration = iteration + 1)
suspend fun execute() = block(iteration)
}
产生错误的行:
val job: PersistJob = ...
log.debug("start job id($id): $job")`// job.toString()
堆栈跟踪:
at kotlin.reflect.jvm.internal.EmptyContainerForLocal.fail(SourceFile:41)
at kotlin.reflect.jvm.internal.EmptyContainerForLocal.getFunctions(SourceFile:37)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.findFunctionDescriptor(SourceFile:145)
at kotlin.reflect.jvm.internal.KFunctionImpl$descriptor$2.invoke(SourceFile:54)
at kotlin.reflect.jvm.internal.KFunctionImpl$descriptor$2.invoke(SourceFile:34)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(SourceFile:93)
at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(SourceFile:32)
at kotlin.reflect.jvm.internal.KFunctionImpl.getDescriptor(SourceFile)
at kotlin.reflect.jvm.internal.ReflectionFactoryImpl.renderLambdaToString(SourceFile:59)
at kotlin.jvm.internal.Reflection.renderLambdaToString(SourceFile:80)
at kotlin.jvm.internal.Lambda.toString(SourceFile:22)
at java.lang.String.valueOf(String.java:2683)
at java.lang.StringBuilder.append(StringBuilder.java:129)
【问题讨论】:
-
I can't reproduce it in my environment- 怎么会? -
通过崩溃报告。
-
我相信当 android 设备低于 6.0 时会显示此错误。有同样的问题应用程序在设备 6.0 及更高版本上工作,但在 5.0 上没有。我相信这是 Kotlin 的错误
标签: exception reflection lambda kotlin kotlinx.coroutines