From 428948e2025915376ed1cf8b521342dff8ae79d0 Mon Sep 17 00:00:00 2001 From: aleks Date: Tue, 3 Dec 2024 16:57:58 +0100 Subject: [PATCH 1/2] Fixed ConcurrentModificationException when loading populations with unselected plans --- .../application/prepare/scenario/CreateScenarioCutOut.java | 4 +--- 1 file changed, 1 insertion(+), 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 d7450553f5c..868f9121db5 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 @@ -572,9 +572,7 @@ 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); + person.getPlans().removeIf(p -> p != person.getSelectedPlan()); } From 4b4675aa8eeb4cc9e31bbfb8b0c70249ce77378f Mon Sep 17 00:00:00 2001 From: aleks Date: Tue, 3 Dec 2024 18:09:20 +0100 Subject: [PATCH 2/2] Changed to more stable solution (instead of directly manipulating the list-object, we now use the removePlan-method) --- .../application/prepare/scenario/CreateScenarioCutOut.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 868f9121db5..f5ecf5b56ab 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 @@ -572,7 +572,12 @@ public void run(Person person) { } // Remove all unselected plans because these are not handled - person.getPlans().removeIf(p -> p != person.getSelectedPlan()); + List plans = new ArrayList<>(person.getPlans()); + for(Plan p : plans){ + if (p != person.getSelectedPlan()){ + person.removePlan(p); + } + } }