Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-2745

Tree component with empty list of root nodes causes NullPointerException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.8.2
    • 5.8.3
    • tapestry-core

    Description

      An edge case, perhaps, but it seems as though attempting to create a Tree component with no root nodes does not produce an empty list, but throws a null pointer exception.

      java.lang.NullPointerException: Cannot invoke "org.apache.tapestry5.tree.TreeNode.getValue()" because "this.val$node" is null
          at org.apache.tapestry5.corelib.components.Tree$4.render(Tree.java:169) ~[tapestry-core-5.8.2.jar:?]
          at org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:79) ~[tapestry-core-5.8.2.jar:?]
          at org.apache.tapestry5.internal.services.PageRenderQueueImpl.render(PageRenderQueueImpl.java:121) ~[tapestry-core-5.8.2.jar:?]
      

      To the best of my understanding, the fix is straight forward:

      --- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Tree.java
      +++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Tree.java
      @@ -265,7 +265,12 @@ public class Tree
                   writer.element("ul");
                   queue.push(RENDER_CLOSE_TAG);
       
      -            queue.push(toRenderCommand(nodes.first(), true));
      +            TreeNode first = nodes.first();
      +
      +            if (first != null)
      +            {
      +                queue.push(toRenderCommand(first, true));
      +            }
       
                   nodes.rest().each(new Worker<TreeNode>()
                   {
      

      Attachments

        1. TAP5-2745-suggested-fix.patch
          0.8 kB
          Robert Hailey

        Issue Links

          Activity

            People

              ben-ng Ben Weidig
              rhailey Robert Hailey
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: