From 912856844629aa366e0c51911071ce7a042e39bf Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:33:48 +0200 Subject: [PATCH] fix: Fix thread safety in ManagedKeyMappingRegistry --- .../net/blay09/mods/kuma/ManagedKeyMappingRegistry.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kuma-api/common/src/main/java/net/blay09/mods/kuma/ManagedKeyMappingRegistry.java b/kuma-api/common/src/main/java/net/blay09/mods/kuma/ManagedKeyMappingRegistry.java index 97191d0..01d1713 100644 --- a/kuma-api/common/src/main/java/net/blay09/mods/kuma/ManagedKeyMappingRegistry.java +++ b/kuma-api/common/src/main/java/net/blay09/mods/kuma/ManagedKeyMappingRegistry.java @@ -3,6 +3,7 @@ import net.blay09.mods.kuma.api.ManagedKeyMapping; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -10,7 +11,7 @@ public class ManagedKeyMappingRegistry { public static final Comparator COMPARATOR = Comparator.comparingInt((ManagedKeyMapping it) -> it.getBinding().modifiers().size()) .reversed(); - private static final List keyMappings = new ArrayList<>(); + private static final List keyMappings = Collections.synchronizedList(new ArrayList<>()); public static void register(ManagedKeyMapping keyMapping) { keyMappings.add(keyMapping); @@ -18,6 +19,8 @@ public static void register(ManagedKeyMapping keyMapping) { } public static List getKeyMappings() { - return keyMappings.stream().sorted(COMPARATOR).toList(); + synchronized (keyMappings) { + return keyMappings.stream().sorted(COMPARATOR).toList(); + } } }