Menu

#161 TreeListView.RebuildChildren can cause a IndexOutOfRangeException when filtering

C#_v2.7
wont-fix
nobody
None
1
2018-12-12
2016-06-21
Thracx
No

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.

Discussion

  • Thracx

    Thracx - 2016-06-21

    There is more to this bug than I first thought, I'll keep looking into it.

     
  • Phillip Piper

    Phillip Piper - 2018-10-06
    • status: open --> wont-fix
     
  • Phillip Piper

    Phillip Piper - 2018-10-06

    Can't reproduce.

     
  • Thracx

    Thracx - 2018-12-12

    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

Log in to post a comment.