From 62421e87ccd0e6c720a6f8d8d248dec6d05d5e2b Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sat, 5 Oct 2024 20:53:07 +0200 Subject: [PATCH] fixed ConcurrentModificationException in clear() --- .../model/src/main/java/pp/battleship/model/ShipMap.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Projekte/battleship/model/src/main/java/pp/battleship/model/ShipMap.java b/Projekte/battleship/model/src/main/java/pp/battleship/model/ShipMap.java index dfab415..3bd5c20 100644 --- a/Projekte/battleship/model/src/main/java/pp/battleship/model/ShipMap.java +++ b/Projekte/battleship/model/src/main/java/pp/battleship/model/ShipMap.java @@ -105,9 +105,8 @@ public class ShipMap { * Removes all items from the map and triggers corresponding removal events for each. */ public void clear() { - for (Item item : items) { - items.remove(item); - notifyListeners(new ItemRemovedEvent(item, this)); + while (!items.isEmpty()) { + notifyListeners(new ItemRemovedEvent(items.removeFirst(), this)); } }