Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-5208

Review use of getChildNodeCount in AbstractTreeModel getChildNodes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 9.6.3
    • 10.0.0, 9.6.2
    • None
    • Security Level: Jimmy

      Steps to Reproduce

      Run in CE (not fiddle)

       

      https://zkfiddle.org/sample/2nb3e9e/8-Tree-select-all-with-load-on-demand

       

      https://github.com/zkoss/zk/blob/master/zul/src/org/zkoss/zul/AbstractTreeModel.java#L906-L914

      In abstract tree model, when calling getChildNodes of a target Node, the current process is to retrieve the childNodeCount (the number of all descendant nodes, direct and indirect).

      Then, to do a for loop from zero to that count, and fetch the target node getChild at that value.

      Since getChild only retrieves direct children (not indirect descendants), this may trigger a lot of calls to getChild() returned with a null value because there is no child at that index.

      Assuming the structrure below, getChildNodeCount of A is 6, but only getChild(0) is a useful call.

      A

      --B

      --C1

      --C2

      --C3

      --C4

      --C5

       

      TODO

      Review if getChildCount (which returns direct children count only) instead of getChildNodeCount (which returns direct children and also their own descendant count) would be appropriate for TreeModel.

      This could affect other implementation than DefaultTreeModel and AbstractTreeModel.

      If a change is not warranted, we should update Javadoc to reflect that getChild can be called out of bounds, and need to return null in that case.

      Debug Information

      Calling a child at an empty index returns Null in DefaultTreeModel, but it might not be clear to developers that TreeModel may call index out of the child collection size when implementing their own tree models.

       

            jumperchen jumperchen
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: