Skip to content

Commit

Permalink
Ensure contract of Collections#synchronizedList
Browse files Browse the repository at this point in the history
Looping over a synchronized list must either manually synchronize over the list or use the "atomic" List#forEach method.
  • Loading branch information
weisJ committed Aug 1, 2021
1 parent b926d95 commit a9ae43f
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public void dispatchEvent(final E event) {
}

public void dispatchEvent(final E event, final BiConsumer<T, E> consumer) {
for (T listener : listenerList) {
if (listener != null) {
consumer.accept(listener, event);
}
}
listenerList.forEach(listener -> {
if (listener != null) consumer.accept(listener, event);
});
}
}

0 comments on commit a9ae43f

Please sign in to comment.