From 9a31cbdc52f8ee0ea2326c3b6461ac5673826594 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Sun, 1 Aug 2021 12:27:07 +0200 Subject: [PATCH] Dispatch events on a copy of the listener list This allows for listeners to be removed/added while dispatching. --- .../weisj/darklaf/theme/event/ThemeEventSupport.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemeEventSupport.java b/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemeEventSupport.java index 13d50812..0a91fbb5 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemeEventSupport.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemeEventSupport.java @@ -43,8 +43,10 @@ public class ThemeEventSupport consumer) { - listenerList.forEach(listener -> { - if (listener != null) consumer.accept(listener, event); - }); + synchronized (listenerList) { + new ArrayList<>(listenerList).forEach(listener -> { + if (listener != null) consumer.accept(listener, event); + }); + } } }