From 68381ccf322ad24f60d08f401dc193ebf1f953d5 Mon Sep 17 00:00:00 2001 From: Gabriel Souza Date: Sun, 5 Nov 2023 14:41:39 -0300 Subject: [PATCH] fix: concurrent modification exception in kotlin 1.9.20 and compose 1.5.10 (#245) * fix: concurrent modification exception in kotlin 1.9.20 and compose 1.5.10 * copying collection * removing unsed import --- .../cafe/adriel/voyager/core/model/ScreenModelStore.kt | 2 +- .../concurrent/ThreadSafeMap.native.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/model/ScreenModelStore.kt b/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/model/ScreenModelStore.kt index da4d6216..dbfa037b 100644 --- a/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/model/ScreenModelStore.kt +++ b/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/model/ScreenModelStore.kt @@ -113,7 +113,7 @@ public object ScreenModelStore : ScreenDisposable { private fun Map.onEachHolder(holderKey: String, block: (String) -> Unit) = - asSequence() + toMap() // copy .filter { it.key.startsWith(holderKey) } .map { it.key } .forEach(block) diff --git a/voyager-core/src/nativeMain/kotlin/cafe.adriel.voyager.core/concurrent/ThreadSafeMap.native.kt b/voyager-core/src/nativeMain/kotlin/cafe.adriel.voyager.core/concurrent/ThreadSafeMap.native.kt index e96cdbf8..10a13c83 100644 --- a/voyager-core/src/nativeMain/kotlin/cafe.adriel.voyager.core/concurrent/ThreadSafeMap.native.kt +++ b/voyager-core/src/nativeMain/kotlin/cafe.adriel.voyager.core/concurrent/ThreadSafeMap.native.kt @@ -29,11 +29,11 @@ public actual class ThreadSafeMap( } override val entries: MutableSet> - get() = delegate.entries + get() = synchronized(syncObject) { delegate.entries.toMutableSet() } override val keys: MutableSet - get() = delegate.keys + get() = synchronized(syncObject) { delegate.keys.toMutableSet() } override val values: MutableCollection - get() = delegate.values + get() = synchronized(syncObject) { delegate.values.toMutableList() } override fun clear() { synchronized(syncObject) { delegate.clear() }