Removing related entities in nested Datasource in 6.4RC

Hi,
I was removing related entities in nested datasources with button click event:


public void onButton_Click() {
    for (MyNestedEntity ne : MyNestedDatasourceDs.getItems())
        MyNestedDatasourceDs.removeItem(ne);
}

That works perfectly in 6.3, in 6.4 gives a ConcurrentModificationException.
Is this a Bug? What’s the way to do it?

Thanks

Hi Pedro,

Thank you for pointing out this difference - we’ll mention it in the release notes.

The issue is caused by the fact that getItems() method now returns an unmodifiable collection instead of full copy as previously. So you now cannot modify the collection when iterating through it at the same time. But you can do the same as follows:


for (UUID id : orderLinesDs.getItemIds()) {
    orderLinesDs.removeItem(orderLinesDs.getItem(id));
}

or


for (OrderLine orderLine : new ArrayList<>(orderLinesDs.getItems())) {
    orderLinesDs.removeItem(orderLine);
}
1 Like