diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/AbstractConcurrentPermissionService.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/AbstractConcurrentPermissionService.kt index 933b24a9d..5bfd5f14d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/AbstractConcurrentPermissionService.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/AbstractConcurrentPermissionService.kt @@ -12,6 +12,9 @@ package net.mamoe.mirai.console.permission import net.mamoe.mirai.console.permission.PermissibleIdentifier.Companion.grantedWith import java.util.concurrent.CopyOnWriteArrayList +/** + * + */ @ExperimentalPermission public abstract class AbstractConcurrentPermissionService

: PermissionService

{ protected abstract val permissions: MutableMap @@ -28,9 +31,8 @@ public abstract class AbstractConcurrentPermissionService

: Perm override fun register(id: PermissionId, description: String, base: PermissionId): P { grantedPermissionsMap[id] = CopyOnWriteArrayList() // mutations are not quite often performed val instance = createPermission(id, description, base) - if (permissions.putIfAbsent(id, instance) != null) { - throw DuplicatedPermissionRegistrationException("Duplicated Permission registry. new: $instance, old: ${permissions[id]}") - } + val old = permissions.putIfAbsent(id, instance) + if (old != null) throw DuplicatedPermissionRegistrationException(instance, old) return instance } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/BuiltInPermissionServices.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/BuiltInPermissionServices.kt index 7cd656046..d873ffcc9 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/BuiltInPermissionServices.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/BuiltInPermissionServices.kt @@ -35,9 +35,8 @@ public object AllGrantPermissionService : PermissionService { base: PermissionId ): PermissionImpl { val new = PermissionImpl(id, description, base) - if (all.putIfAbsent(id, new) != null) { - throw DuplicatedPermissionRegistrationException("Duplicated Permission registry: ${all[id]}") - } + val old = all.putIfAbsent(id, new) + if (old != null) throw DuplicatedPermissionRegistrationException(new, old) return new } @@ -67,9 +66,8 @@ public object AllDenyPermissionService : PermissionService { base: PermissionId ): PermissionImpl { val new = PermissionImpl(id, description, base) - if (all.putIfAbsent(id, new) != null) { - throw DuplicatedPermissionRegistrationException("Duplicated Permission registry: ${all[id]}") - } + val old = all.putIfAbsent(id, new) + if (old != null) throw DuplicatedPermissionRegistrationException(new, old) return new } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/DuplicatedPermissionRegistrationException.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/DuplicatedPermissionRegistrationException.kt index b521e1703..39cbb2807 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/DuplicatedPermissionRegistrationException.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/DuplicatedPermissionRegistrationException.kt @@ -7,14 +7,12 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ -@file:Suppress("unused") +@file:Suppress("unused", "MemberVisibilityCanBePrivate", "CanBeParameter") package net.mamoe.mirai.console.permission @ExperimentalPermission -public open class DuplicatedPermissionRegistrationException : Exception { - public constructor() : super() - public constructor(message: String?) : super(message) - public constructor(message: String?, cause: Throwable?) : super(message, cause) - public constructor(cause: Throwable?) : super(cause) -} \ No newline at end of file +public class DuplicatedPermissionRegistrationException( + newInstance: Permission, + public val existingInstance: Permission +) : Exception("Duplicated Permission registry. new: $newInstance, existing: $existingInstance") \ No newline at end of file