Kotlinx.coroutines: native-mt: MutableStateFlow cannot be frozen

Created on 15 Jul 2020  路  4Comments  路  Source: Kotlin/kotlinx.coroutines

Version: 1.3.7-native-mt-1.4-M2

When freezing MutableStateFlow and changing the value like this:

import kotlinx.coroutines.flow.MutableStateFlow
import kotlin.native.concurrent.freeze

fun freezeExample() {
    val stateFlow = MutableStateFlow(0)
    stateFlow.freeze()
    stateFlow.value = 1
}

The following exception is thrown:

Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.flow.StateFlowImpl@805b40c8
    at 0   common                              0x00000001074f6860 kfun:kotlin.Throwable#<init>(kotlin.String?){} + 92
    at 1   common                              0x00000001074ef9c0 kfun:kotlin.Exception#<init>(kotlin.String?){} + 88
    at 2   common                              0x00000001074ef3fc kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 88
    at 3   common                              0x00000001075237b4 kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 88
    at 4   common                              0x0000000107524bc0 ThrowInvalidMutabilityException + 468
    at 5   common                              0x00000001088a3f60 MutationCheck + 132
    at 6   common                              0x0000000107637d60 kfun:kotlinx.coroutines.flow.StateFlowImpl.<set-sequence>#internal + 92
    at 7   common                              0x00000001076385f4 kfun:kotlinx.coroutines.flow.StateFlowImpl.<set-value>#internal + 900
    at 8   common                              0x00000001082aa324 kfun:com.superthomaslab.hueessentials.common#freezeExample(){} + 288
    at 9   common                              0x0000000108863b84 objc2kotlin.24665 + 96
    at 10  HueEssentials-dev                   0x00000001047e0858 $s17HueEssentials_dev11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtFTo + 232
    at 11  UIKitCore                           0x000000018705b988 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 10901896
    at 12  UIKitCore                           0x000000018705d768 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 10909544
    at 13  UIKitCore                           0x0000000187063164 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 10932580
    at 14  UIKitCore                           0x00000001867d307c 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 1953916
    at 15  UIKitCore                           0x000000018705f178 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 10916216
    at 16  UIKitCore                           0x000000018705f4d4 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 10917076
    at 17  UIKitCore                           0x0000000187065358 UIApplicationMain + 1944
    at 18  HueEssentials-dev                   0x00000001047e1aac main + 80
    at 19  libdyld.dylib                       0x0000000182d0d2dc 322C4E05-D0CF-33F5-B996-CE5C67DF59B6 + 4828
native

Most helpful comment

Fixed in 1.4.2-native-mt

All 4 comments

Fixed in 1.3.9-native-mt-2

@qwwdfsad could you reopen this issue, please? Unfortunately MutableStateFlow no longer works with 1.4.1-native-mt.

Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.flow.StateFlowImpl@82e51d08
    at 0   common                              0x0000000105a04d8c kfun:kotlin.Throwable#<init>(kotlin.String?){} + 96
    at 1   common                              0x00000001059fd158 kfun:kotlin.Exception#<init>(kotlin.String?){} + 92
    at 2   common                              0x00000001059fd3c8 kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 92
    at 3   common                              0x0000000105a32cb4 kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 92
    at 4   common                              0x0000000105a3407c ThrowInvalidMutabilityException + 336
    at 5   common                              0x0000000107018cdc MutationCheck + 156
    at 6   common                              0x0000000105b5273c kfun:kotlinx.coroutines.flow.StateFlowImpl.<set-sequence>#internal + 96
    at 7   common                              0x0000000105b53050 kfun:kotlinx.coroutines.flow.StateFlowImpl.updateState#internal + 948
    at 8   common                              0x0000000105b52a48 kfun:kotlinx.coroutines.flow.StateFlowImpl.<set-value>#internal + 248
    at 9   common                              0x0000000105e89ed8 kfun:com.superthomaslab.hueessentials.common#freezeExample(){} + 292
    at 10  common                              0x0000000106fcbf84 objc2kotlin.26222 + 100
    at 11  HueEssentials-dev                   0x0000000102987e0c $s17HueEssentials_dev11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtFTo + 212
    at 12  UIKitCore                           0x00000001a16a2540 05147936-B875-3EF3-94DB-9C8869BB0E34 + 12334400
    at 13  UIKitCore                           0x00000001a16a45a8 05147936-B875-3EF3-94DB-9C8869BB0E34 + 12342696
    at 14  UIKitCore                           0x00000001a16aa004 05147936-B875-3EF3-94DB-9C8869BB0E34 + 12365828
    at 15  UIKitCore                           0x00000001a0d01950 05147936-B875-3EF3-94DB-9C8869BB0E34 + 2238800
    at 16  UIKitCore                           0x00000001a16a5db0 05147936-B875-3EF3-94DB-9C8869BB0E34 + 12348848
    at 17  UIKitCore                           0x00000001a16a61dc 05147936-B875-3EF3-94DB-9C8869BB0E34 + 12349916
    at 18  UIKitCore                           0x00000001a16aba74 UIApplicationMain + 168
    at 19  HueEssentials-dev                   0x0000000102988e58 main + 88
    at 20  libdyld.dylib                       0x000000019e92d6c0 BA60CB9E-95C5-3646-BEED-D313E15586CF + 5824

Fixed in 1.4.2-native-mt

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Leftwitch picture Leftwitch  路  3Comments

elizarov picture elizarov  路  3Comments

mttmllns picture mttmllns  路  3Comments

ScottPierce picture ScottPierce  路  3Comments

sky87 picture sky87  路  3Comments