Program: 8987
Project: 8987
Buggy source:
/** 
 * TODO: clean up. workaround for OAK-426 <p> Create the tree at the specified relative path including all missing intermediate trees using the specified   {@code primaryTypeName}. This method treats ".." parent element and "." as current element and resolves them accordingly; in case of a relative path containing parent elements this may lead to tree creating outside the tree structure defined by this   {@code NodeUtil}.
 * @param relativePath    A relative OAK path that may contain parent andcurrent elements.
 * @param primaryTypeName A oak name of a primary node type that is usedto create the missing trees.
 * @return The node util of the tree at the specified {@code relativePath}.
 * @throws AccessDeniedException If the any intermediate tree does not existand cannot be created.
 */
@Nonnull public NodeUtil getOrAddTree(String relativePath,String primaryTypeName) throws AccessDeniedException {
  if (relativePath.indexOf('/') == -1) {
    return getOrAddChild(relativePath,primaryTypeName);
  }
 else {
    Tree t=TreeUtil.getTree(tree,relativePath);
    if (t == null || !t.exists()) {
      NodeUtil target=this;
      for (      String segment : Text.explode(relativePath,'/')) {
        if (PathUtils.denotesParent(segment)) {
          target=target.getParent();
        }
 else         if (target.hasChild(segment)) {
          target=target.getChild(segment);
        }
 else         if (!PathUtils.denotesCurrent(segment)) {
          target=target.addChild(segment,primaryTypeName);
        }
      }
      return target;
    }
 else {
      return new NodeUtil(t);
    }
  }
}

Fixed version (ground truth):
/** 
 * TODO: clean up. workaround for OAK-426 <p> Create the tree at the specified relative path including all missing intermediate trees using the specified   {@code primaryTypeName}. This method treats ".." parent element and "." as current element and resolves them accordingly; in case of a relative path containing parent elements this may lead to tree creating outside the tree structure defined by this   {@code NodeUtil}.
 * @param relativePath    A relative OAK path that may contain parent andcurrent elements.
 * @param primaryTypeName A oak name of a primary node type that is usedto create the missing trees.
 * @return The node util of the tree at the specified {@code relativePath}.
 * @throws AccessDeniedException If the any intermediate tree does not existand cannot be created.
 */
@Nonnull public NodeUtil getOrAddTree(String relativePath,String primaryTypeName) throws AccessDeniedException {
  if (relativePath.indexOf('/') == -1) {
    return getOrAddChild(relativePath,primaryTypeName);
  }
 else {
    Tree t=TreeUtil.getTree(tree,relativePath);
    if (t == null || !t.exists()) {
      NodeUtil target=this;
      for (      String segment : Text.explode(relativePath,'/')) {
        if (PathUtils.denotesParent(segment)) {
          target=target.getParent();
        }
 else         if (target.hasChild(segment)) {
          target=target.getChild(segment);
        }
 else         if (!PathUtils.denotesCurrent(segment)) {
          target=target.addChild(segment,primaryTypeName);
        }
      }
      if (target == null) {
        throw new AccessDeniedException();
      }
      return target;
    }
 else {
      return new NodeUtil(t);
    }
  }
}