From 95aea01e96ab025baab090693e2dc40d7933a214 Mon Sep 17 00:00:00 2001 From: Adrian Paschkowski Date: Sun, 23 Jun 2024 16:21:41 +0200 Subject: [PATCH] Fix concurrency issues with voice- and thread members --- .../javacord/core/entity/channel/ServerThreadChannelImpl.java | 3 ++- .../javacord/core/entity/channel/ServerVoiceChannelImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/javacord-core/src/main/java/org/javacord/core/entity/channel/ServerThreadChannelImpl.java b/javacord-core/src/main/java/org/javacord/core/entity/channel/ServerThreadChannelImpl.java index 7752b99c80..37efe6dc71 100644 --- a/javacord-core/src/main/java/org/javacord/core/entity/channel/ServerThreadChannelImpl.java +++ b/javacord-core/src/main/java/org/javacord/core/entity/channel/ServerThreadChannelImpl.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; /** * The implementation of {@link ServerThreadChannel}. @@ -94,7 +95,7 @@ public ServerThreadChannelImpl(final DiscordApiImpl api, final ServerImpl server lastMessageId = data.hasNonNull("last_message_id") ? data.get("last_message_id").asLong() : 0; rateLimitPerUser = data.get("rate_limit_per_user").asInt(0); - members = new HashSet<>(); + members = ConcurrentHashMap.newKeySet(); if (data.hasNonNull("member")) { // If userId is not included, that means this came from a GUILD_CREATE event // This means the userId is the bot's and the thread id is from this thread diff --git a/javacord-core/src/main/java/org/javacord/core/entity/channel/ServerVoiceChannelImpl.java b/javacord-core/src/main/java/org/javacord/core/entity/channel/ServerVoiceChannelImpl.java index 4cb3788e8b..ccf46fa8a3 100644 --- a/javacord-core/src/main/java/org/javacord/core/entity/channel/ServerVoiceChannelImpl.java +++ b/javacord-core/src/main/java/org/javacord/core/entity/channel/ServerVoiceChannelImpl.java @@ -11,11 +11,11 @@ import org.javacord.core.listener.channel.server.voice.InternalServerVoiceChannelAttachableListenerManager; import java.util.Collections; -import java.util.HashSet; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; /** @@ -37,7 +37,7 @@ public class ServerVoiceChannelImpl extends TextableRegularServerChannelImpl /** * The ids of the connected users of this server voice channel. */ - private final Set connectedUsers = new HashSet<>(); + private final Set connectedUsers = ConcurrentHashMap.newKeySet(); /** * Creates a new server voice channel object.