From 77bf4a43fd11e1f3c0a5636a9dbdea8f5661c8e9 Mon Sep 17 00:00:00 2001 From: Aleksander1234519 <111151521+Aleksander1234519@users.noreply.github.com> Date: Wed, 11 Dec 2024 09:26:40 +0100 Subject: [PATCH] Fixed ConcurrentModificationException in scenario-cutout util (#3624) * Fixed ConcurrentModificationException when loading populations with unselected plans * Changed to more stable solution (instead of directly manipulating the list-object, we now use the removePlan-method) --------- Co-authored-by: rakow --- .../prepare/scenario/CreateScenarioCutOut.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contribs/application/src/main/java/org/matsim/application/prepare/scenario/CreateScenarioCutOut.java b/contribs/application/src/main/java/org/matsim/application/prepare/scenario/CreateScenarioCutOut.java index 4dcd8a6bf5a..909d311d64f 100644 --- a/contribs/application/src/main/java/org/matsim/application/prepare/scenario/CreateScenarioCutOut.java +++ b/contribs/application/src/main/java/org/matsim/application/prepare/scenario/CreateScenarioCutOut.java @@ -590,9 +590,12 @@ public void run(Person person) { } // Remove all unselected plans because these are not handled - person.getPlans().stream() - .filter(p -> p != person.getSelectedPlan()) - .forEach(person::removePlan); + List plans = new ArrayList<>(person.getPlans()); + for(Plan p : plans){ + if (p != person.getSelectedPlan()){ + person.removePlan(p); + } + } }