From 3ffdde0ca253979864ae8dbfc68ffc6b9509490b Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 19 Dec 2020 08:42:35 +0800 Subject: [PATCH] Use ConcurrentHashMap for Bot._instance, fix #727 --- mirai-core-api/src/commonMain/kotlin/Bot.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mirai-core-api/src/commonMain/kotlin/Bot.kt b/mirai-core-api/src/commonMain/kotlin/Bot.kt index 35a5dd8d3..2432b887d 100644 --- a/mirai-core-api/src/commonMain/kotlin/Bot.kt +++ b/mirai-core-api/src/commonMain/kotlin/Bot.kt @@ -24,8 +24,7 @@ import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.MiraiExperimentalApi import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.PlannedRemoval -import java.util.* -import kotlin.NoSuchElementException +import java.util.concurrent.ConcurrentHashMap /** * 登录, 返回 [this] @@ -153,14 +152,14 @@ public interface Bot : CoroutineScope, ContactOrBot, UserOrBot { public companion object { @Suppress("ObjectPropertyName") - internal val _instances: WeakHashMap = WeakHashMap() + internal val _instances: ConcurrentHashMap = ConcurrentHashMap() /** * 复制一份此时的 [Bot] 实例列表. */ @JvmStatic public val instances: List - get() = _instances.values.filterNotNull() + get() = _instances.values.toList() /** * 复制一份此时的 [Bot] 实例列表.