From d0c4463ab372460ce6f16ec09ea975448423ed66 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 28 Oct 2022 21:29:38 -0400 Subject: [PATCH] Avoid concurrency crashes in SourceManager --- .../main/java/eu/kanade/tachiyomi/source/SourceManager.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt index 94f03372e..dfe3a7f3a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt @@ -21,6 +21,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import rx.Observable import uy.kohesive.injekt.injectLazy +import java.util.concurrent.ConcurrentHashMap class SourceManager( private val context: Context, @@ -31,7 +32,7 @@ class SourceManager( private val scope = CoroutineScope(Job() + Dispatchers.IO) - private var sourcesMap = emptyMap() + private var sourcesMap = ConcurrentHashMap() set(value) { field = value sourcesMapFlow.value = field @@ -39,7 +40,7 @@ class SourceManager( private val sourcesMapFlow = MutableStateFlow(sourcesMap) - private val stubSourcesMap = mutableMapOf() + private val stubSourcesMap = ConcurrentHashMap() val catalogueSources: Flow> = sourcesMapFlow.map { it.values.filterIsInstance() } val onlineSources: Flow> = catalogueSources.map { sources -> sources.filterIsInstance() } @@ -48,7 +49,7 @@ class SourceManager( scope.launch { extensionManager.installedExtensionsFlow .collectLatest { extensions -> - val mutableMap = mutableMapOf(LocalSource.ID to LocalSource(context)) + val mutableMap = ConcurrentHashMap(mapOf(LocalSource.ID to LocalSource(context))) extensions.forEach { extension -> extension.sources.forEach { mutableMap[it.id] = it