Eden-06 / FRaMED-2.0

FRaMED 2.0 is the reimplementation of the Full-fledged Role Modeling EDitor allowing the graphical specification of Role-based Software Systems by means of compartments (aka. contexts), objects, roles, and relationships.
Eclipse Public License 2.0
3 stars 0 forks source link

ConcurrentModificationException while generating tests #20

Open floa93 opened 5 years ago

floa93 commented 5 years ago

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

zointblackbriar commented 4 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

zointblackbriar commented 4 years ago

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);
    }
}