2017-12-29 84 views
2

kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Introspecting local functions, lambdas, anonymous functions and local variables is not yet fully supported in Kotlin reflectionKotlin /アンドロイド - ラムダとデータクラスでKotlinReflectionInternalError

この例外は、データクラスのtoString()から来ています。

データクラスにはラムダが含まれています。

私の環境では再生できません。

ラムダを除外するにはtoString()をオーバーライドする必要がありますか?または、ラムダはデータクラスではまったく使用できません。エラーを生成

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) 
+0

「私は自分の環境でそれを再現できません」 - どうしてですか? – voddan

+1

クラッシュレポートを経由します。 –

答えて

2

それはKotlinのラムダのバグのように見えます。

({i: Int -> true}).toString() 

私のアドバイスあなたがyoutrack.jetbrains.com/issues/KT上の問題を投稿し、チームはそれについて言っている参照してください。

このコードは、例外を再現するのに十分です。

+0

あなたの環境は?それは私の 'Kotlinバージョン1.1.51(JRE 1.8.0_144-b01)' –

+0

https://try.kotlinlang.org 1.2.10 JVM – voddan

+0

でうまくいきます。そして 'System.getProperty(" java.version ")'は '1.8.0_45'を返します。だから、Javaのバージョンの問題ではないようです。 –

関連する問題