Open floa93 opened 5 years ago
Essentially, the ConcurrentModificationException is used to fail-fast when something we are iterating on is modified.
Solutions: 1) Using an iterator directly. 2) Not Removing During Iteration 3) Using removeIf() 4) Filtering Using Streams
@Source: https://www.baeldung.com/java-concurrentmodificationexception
Modified Function:
private void deleteFulfillmentsWithFilledRoleGroups(EList<Relation> relations) {
List<Fulfillment> fulfillmentsToDelete = new ArrayList<Fulfillment>();
//Added a new list to be deleted
List<Fulfillment> fulToBeRemoved = new ArrayList<Fulfillment>();
for(Relation relation : relations) {
if(relation instanceof crom_l1_composed.Fulfillment) {
Fulfillment ful = (Fulfillment) relation;
if(ful.getFilled() instanceof RoleGroup) {
fulfillmentsToDelete.add(ful);
}
}
for(Fulfillment ful : fulfillmentsToDelete) {
//Added the objects into a List data structure
fulToBeRemoved.add(ful);
}
//We will delete all without deleting in an iteration
fulfillmentsToDelete.removeAll(fulToBeRemoved);
}
}
File: org.framed.iorm.transformation.test/src/org/framed/iorm/transformation/test/model/test/testgeneration/TestGenerator.java Method: deleteFulfillmentsWithFilledRoleGroups
for(Fulfillment ful : fulfillmentsToDelete) { relations.remove(ful); }
tries to modify the list while iterating through it