The CDOStoreUnorderedEList changes the order of a list during remove.
This is the code of CDOStoreUnorderedEList:
public E remove(int index)
boolean oldObjectIsLast = index == size() - 1;
E oldObject = super.remove(index);
move(index, size() - 1);
A move is performed if the removed object was not the last object in the list.
Since a RemoveCommand stores its remove indices in the owing list for undoing, this additional move destroys the ability to properly undo RemoveCommands.
Consider the following list of objects in an CDOStoreUnorderedEList. For simplicity the objects in the list are represented by their id:
Add element 4 -> 1,2,3,4
Remove Element 1: 4,2,3 (this changed order is due to the additional move)
Remove Element 4: -> 3,2 (this changed order is due to the additional move)
undo: 4,3,2 (The undo of RemoveCommand inserts 4 at position 0)
undo: 1,4,3,2 (The undo of RemoveCommand inserts 1 at position 0)
undo: 1,4,3 (The undo of AddCommand removes element at position 3)
So we end up with a list that contains elements 1,4,3 instead of 1,2,3.
I am quite sure that this is a bug and I do not see a reason for this additional move. If the move is skipped everything works just fine.
Any thoughts on this?
Thanks in advance