https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Andy Victors

05/23/2019, 9:10 AM
Why do I get
kotlin.native.concurrent.InvalidMutabilityException
[called from iOS] in the
init()
method by setting the
value
? During init() the object should not be frozen, right? (confirmed by println in code).
Copy code
var value: Float
    init {
        println("MetricReference:init (${metric.name} ): Frozen? -> ${this.isFrozen()} ")
        this.metric = metric
        this.metric.addObserver(this)
        this.value = metric.getValue()
    }
r

ribesg

05/23/2019, 10:32 AM
I don’t see any problem in this code, it should work I think. I don’t know when the object is supposed to be frozen though
a

Andy Victors

05/23/2019, 11:03 AM
Apparently the object becomes frozen after addObserver() line. Could someone from Kotlin authors explain what mechanism is taking place here?
Wait, sorry. I know the answer - in addObserver() current objet is added to the frozenCopyOnWriteList<> from Stately library. I have already asked lib author to explain this behaviour.
b

basher

05/23/2019, 12:48 PM
You can call ensureNeverFrozen() on an object you expect to never be frozen, and then you’ll get an exception with a trace that shows where it’s being frozen
👍 1