-
Bug
-
Resolution: Fixed
-
Normal
-
6.0.0, Freshly
Problem Description
I accidentally create a example to set tree Model's selected item to an non-existing tree node. It means this tree node cannot be found in tree's model.
This situation make loop in getPath() method a infinite loop.
Root Cause
org.zkoss.zul.DefaultTreeModel.java
@Override public int[] getPath(TreeNode<E> child) { final TreeNode<E> root = getRoot(); List<Integer> p = new ArrayList<Integer>(); while (root != child) { TreeNode<E> parent = child.getParent(); if (parent != null) { for (int i = 0, j = parent.getChildCount(); i < j; i++) { if (parent.getChildAt(i) == child) { p.add(0, i); break; } } child = parent; } } final Integer[] objs = p.toArray(new Integer[p.size()]); final int[] path = new int[objs.length]; for (int i = 0; i < objs.length; i++) path[i] = objs[i].intValue(); return path; }
When child is a tree node that is not a child node of the tree model. child.getParent() is null, and root!= child is always true thus the loop won't stop forever.