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

NPE when expand all node of Tree by set isOpen = true for all TreeItem

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • 8.0.1
    • 8.0.0
    • None
    • None
    • ZK 8.0.1 S3

      when you has a tree at latest three level. with init with all node is closed.
      add code to set isOpen = true to all node to expand all tree node.

      with prev 8.0.0, code do well and all job done at one request.
      from 8.0.0 it will create node at first request, and do render at second request (second request fire by javascript code and is fire ON_RENDER event)

      code at tree class, block handle event ON_RENDER:

                                        for (Treeitem ti : items) {
      					if (ti.isRendered())
      						continue;
      					int i = ti.getIndex();
      					if (maxItem == null) {
      						maxItem = ti;
      						maxIndex = i;
      					}
      					if (i > maxIndex) {
      						maxItem = ti;
      						maxIndex = i;
      					}
      					
      					ti.getChildren().clear();
      					Treechildren parent = (Treechildren) ti.getParent();
      					Object childNode = getAssociatedNode(ti, this);
      					renderChildren0(renderer, parent, ti, childNode, i);
      				}
      

      when render node at level 2. line ti.getChildren().clear(); will clear all child node.
      so when render not at level 3 code getAssociatedNode(ti, this) thru a NPE.

      below is code to re-proceduce bug:

      // build tree when init page
                    DefaultTreeNode<String> rootNode = new DefaultTreeNode<>("root", new  ArrayList<DefaultTreeNode<String>>());
      		
      		addChildNode (rootNode, 1, 3);
      		
      		for (TreeNode<String> nodeLv1:rootNode.getChildren()){
      			addChildNode (nodeLv1, 2, 3);
      			
      			for (TreeNode<String> nodeLv2:nodeLv1.getChildren()){
      				addChildNode (nodeLv2, 3, 3);
      			}
      		}
      		
      		DefaultTreeModel<String> model = new DefaultTreeModel<>(rootNode);
      		
      		expandAllTree = new Tree();
      		expandAllTree.setModel(model);
      		
      		this.appendChild(expandAllTree);
      
      // function add child node
      	public void addChildNode (TreeNode<String> node, int level, int num){
      		for (int i = 0; i < num; i++){
      			DefaultTreeNode<String> child = new DefaultTreeNode<String> (String.valueOf(level) + "_" + String.valueOf(i), new ArrayList<DefaultTreeNode<String>>());
      			node.add(child);
      		}
      			
      	}
      
      // function to expand tree
                protected void collapseTree (Component treeObject, boolean isOpen){	
      		if (treeObject instanceof Treeitem) {
      			Treeitem treeitem = (Treeitem) treeObject;
      			treeitem.setOpen(isOpen);
      		}
      		Collection<?> com = treeObject.getChildren();
      		if (com != null) {
      			for (Iterator<?> iterator = com.iterator(); iterator.hasNext();) {
      				collapseTree((Component) iterator.next(), isOpen);
      
      			}
      		}
      	}
      
      // call collapseTree in event handle button 
              collapseTree (expandAllTree, true);
      

      below is full NPE message

      java.lang.NullPointerException
      at org.zkoss.zul.Tree.getTreeitemPath(Tree.java:2385)
      at org.zkoss.zul.Tree.getAssociatedNode(Tree.java:2372)
      at org.zkoss.zul.Tree.service(Tree.java:2749)
      at org.zkoss.zk.ui.impl.DesktopImpl.service(DesktopImpl.java:713)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1306)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:611)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:485)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:494)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:821)
      at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1685)
      at org.eclipse.jetty.servlets.PushCacheFilter.doFilter(PushCacheFilter.java:119)
      at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)
      at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
      at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
      at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158)
      at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
      at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
      at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
      at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
      at org.eclipse.jetty.server.Server.handle(Server.java:517)
      at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
      at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
      at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
      at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
      at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
      at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
      at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
      at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
      at java.lang.Thread.run(Thread.java:745)

            christopherszu christopherszu
            hiepgau hiepgau
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours
                2h