Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-11863

AbstractItem#getAncestor interprets the depth argument incorrectly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • Testing JCR Mock 1.6.10
    • Testing
    • None

    Description

      The javadocs for "Item javax.jcr.Item.getAncestor(int depth)" describes the depth argument as:

      depth = 0 returns the root node of a workspace.
      depth = 1 returns the child of the root node along the path to this Item.
      depth = 2 returns the grandchild of the root node along the path to this Item.
      And so on to depth = n, where n is the depth of this Item, which returns this Item itself.

      However, the org.apache.sling.testing.mock.jcr.AbstractItem#getAncestor implementation is using "ResourceUtil.getParent(getPath(), depth)" which interprets the second argument as:

      level = 0 returns the path.
      level = 1 returns the parent of path, if it exists, null otherwise.
      level = 2 returns the grandparent of path, if it exists, null otherwise.

       

      Expected:

      AbstractItem#getAncestor should resolve the ancestor path as the item depth minus the supplied depth argument.

      this.session.getItem(ResourceUtil.getParent(getPath(), getDepth() - depth));

      Attachments

        Issue Links

          Activity

            People

              enorman Eric Norman
              enorman Eric Norman
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: