TreeListView.RebuildChildren can cause a IndexOutOfRangeException when filtering
ObjectListView - ListView on caffeine, guarana and steroids
Brought to you by:
grammarian
BrightIdeasSoftware.TreeListView.RebuildChildren calls this.RebuildObjectMap, even when index is -1, which can happen if the item being rebuild is filtered out. This causes an IndexOutOfRangeException. Wrapping the owning if...else block inside "if (index >= 0)" seems to fix the bug.
There is more to this bug than I first thought, I'll keep looking into it.
Can't reproduce.
Even if it can't be easily reproduced, RebuildObjectMap clearly shouldn't process invalid inputs (i.e. -1). We should either throw an ArgumentOutOfRangeException or use a safe default, like change int i = startIndex to int i = Math.Max(0, startIndex) or wrap it in a index >= 0 like is used many times elsewhere in the code.
Looking at this case, my guess is that this happens when RebuildChildren happens on a model that is not currently shown on the tree (it's parent is collapsed). It might have previously been openned and needs to be refreshed, but is not shown so this method fails due to bad for-loop starting condition for this case.
Last edit: Thracx 2018-12-12