Thread
#multiplatform
    Andy Victors

    Andy Victors

    3 years ago
    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).
    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

    3 years ago
    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
    Andy Victors

    Andy Victors

    3 years ago
    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

    3 years ago
    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