Community
Participate
Working Groups
All the modification methods on an iterator of the WritableList class result in an UnsupportedOperationException even though the operations are supported. The same happens on DetailObservableList and probably also on some subclasses of ObservableSet.
Matthew, while looking at this, I'm not sure what's the best approach to solve this. Right now, ObservableList has an iterator which delegates to the iterator of the wrapped list. What's nice about this is that you get e.g. concurrent modification checks for free (assuming the wrappedIterator itself supports this). However, I don't see how you could implement the mutator methods of the iterator in a generic way in the ObservableList class itself in order to solve the here mentioned problem. E.g. Iterator#remove() cannot simply delegate the removal operation to ObservableList#remove() since, otherwise, the wrappedIterator gets out of synch and would throw a ConcurrentModificationException the next time you access it. Another approach would be to implement the iterator in ObservableList as is done in the AbstractList class of the JDK where the iterator delegates *all* its methods to the enclosing list. This would have the benefit that you only need to implement the iterator in the ObservableList class but (typically) not in subclasses. However, the drawback here is that you loose the free concurrent modification checks and an iterator such as the one implemented in AbstractList is only efficient for RandomAccess lists.
If an implementation of ObservableList is modifiable then the appropriate methods should be overridden. That includes iterator() and listIterator(). Looking through the mutable ObservableList implementations in the databinding bundles, there are two classes where iterator() has not been overridden to make it mutable. The two classes are WritableList and DetailObservableList. It is straight forward to provide mutable implementations of both methods in these two classes and to write the tests for these.
*** This bug has been marked as a duplicate of bug 208434 ***