Eric Norman created SLING-11863:
-----------------------------------
Summary: AbstractItem#getAncestor interprets the depth argument
incorrectly
Key: SLING-11863
URL: https://issues.apache.org/jira/browse/SLING-11863
Project: Sling
Issue Type: Bug
Components: Testing
Reporter: Eric Norman
Assignee: Eric Norman
Fix For: Testing JCR Mock 1.6.10
The
[javadocs|https://javadoc.io/static/javax.jcr/jcr/2.0/javax/jcr/Item.html#getAncestor(int)]
for "Item javax.jcr.Item.getAncestor(int depth)" describes the depth argument
as:
{code:java}
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.{code}
However, the org.apache.sling.testing.mock.jcr.AbstractItem#getAncestor
implementation is using "ResourceUtil.getParent(getPath(), depth)" which
interprets the second argument as:
{code:java}
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.{code}
Expected:
AbstractItem#getAncestor should resolve the ancestor path as the item depth
minus the supplied depth argument.
{code:java}
this.session.getItem(ResourceUtil.getParent(getPath(), getDepth() -
depth));{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)