Alexander Suslov
02/18/2019, 9:58 AM@ThreadLocal
annotation? I have a code:
...
object FooObject {
@ThreadLocal
var bar: String = "first"
}
fun testObj() {
val before = FooObject.bar
println("before = $before")
FooObject.bar = "second"
val after = FooObject.bar
println("after = $after")
}
...
But when I run it, I receive a error:
before = first
Instances of kotlin.Error, kotlin.RuntimeException and subclasses aren't propagated from Kotlin to Objective-C/Swift.
Other exceptions can be propagated as NSError if method has or inherits @Throws annotation.
Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen org.kotlin.mpp.mobile.FooObject@398928
at 0 CoreModule 0x000000010bd9ff36 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 70
at 1 CoreModule 0x000000010bd9fea6 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 70
at 2 CoreModule 0x000000010bda17a6 kfun:kotlin.native.concurrent.InvalidMutabilityException.<init>(kotlin.String)kotlin.native.concurrent.InvalidMutabilityException + 70
at 3 CoreModule 0x000000010bdc6da3 ThrowInvalidMutabilityException + 275
at 4 CoreModule 0x000000010bde18f2 MutationCheck + 50
at 5 CoreModule 0x000000010bd97c63 kfun:org.kotlin.mpp.mobile.FooObject.<set-bar>(kotlin.String) + 67
at 6 CoreModule 0x000000010bd9ed56 kfun:org.kotlin.mpp.mobile.testObj() + 342
at 7 CoreModule 0x000000010bd9eb2e kfun:org.kotlin.mpp.mobile.platformName()kotlin.String + 62
at 8 CoreModule 0x000000010bd9ea82
...
Why the bar
variable is frozen in this case?yuya_horita
02/18/2019, 10:02 AMmutation attempt of frozen org.kotlin.mpp.mobile.FooObject@398928
this message showsyuya_horita
02/18/2019, 10:02 AMyuya_horita
02/18/2019, 10:03 AMyuya_horita
02/18/2019, 10:03 AM@ThreadLocal
object FooObject {
...
Alexander Suslov
02/18/2019, 10:18 AM