From affa0f4c8476b94d82b86bcfc5c11e0725ae9824 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Wed, 2 Apr 2025 23:35:14 +0200 Subject: [PATCH] fix viewable thread-safety --- .../main/java/lol/pyr/znpcsplus/util/Viewable.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java b/plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java index 9001b1e..08b62fe 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/util/Viewable.java @@ -11,13 +11,15 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.stream.Collectors; public abstract class Viewable { - private final static List> all = new ArrayList<>(); + private final static List> all = Collections.synchronizedList(new ArrayList<>()); public static List all() { - all.removeIf(reference -> reference.get() == null); - return all.stream() - .map(Reference::get) - .collect(Collectors.toList()); + synchronized (all) { + all.removeIf(reference -> reference.get() == null); + return all.stream() + .map(Reference::get) + .collect(Collectors.toList()); + } } private boolean queueRunning = false;