There appears to be some inconsistency in FilteredList with how it behaves
when the filter is null. I think if the filter is null, the list is
supposed to show all values. In that case, the filter logic in the add()
and insert() methods is incorrect. Rather than checking
filter != null && filter.include(item)
it should be checking
filter == null || filter.include(item)
Also, the itemUpdated() method in the listListener field sometimes adds
items to the list which are already there. The problem seems to be in the
following if block
if (comparator == null) {
// Add the item to the view
viewIndex = view.add(item);
listListeners.itemInserted(FilteredList.this, viewIndex);
}
I modified the if statement to make a correction, but I'm not sure my
patch is correct. Here's what I replaced the if statement with
// Update the item in the view
int previousViewIndex = view.indexOf(item);
if (previousViewIndex == viewIndex) {
// Update the item in the view
view.update(viewIndex, item);
} else {
// Remove the item from the view
Sequence<T> removed = view.remove(previousViewIndex, 1);
listListeners.itemsRemoved(FilteredList.this, previousViewIndex, removed);
// Re-add the item to the view
viewIndex = view.add(item);
listListeners.itemInserted(FilteredList.this, viewIndex);
}
Again, I'm not sure this is correct but it seems to have resolved the
issue I was having with duplicate items being added to the list.
Cheers,
Michael