Program: 8797
Project: 8797
Buggy source:
void updatePermissionEntries(){
  for (  String principalName : entries.keySet()) {
    NodeBuilder principalRoot=permissionRoot.child(principalName);
    if (!principalRoot.hasProperty(JCR_PRIMARYTYPE)) {
      principalRoot.setProperty(JCR_PRIMARYTYPE,NT_REP_PERMISSION_STORE,Type.NAME);
    }
    NodeBuilder parent=principalRoot.child(nodeName);
    if (!parent.hasProperty(JCR_PRIMARYTYPE)) {
      parent.setProperty(JCR_PRIMARYTYPE,NT_REP_PERMISSION_STORE,Type.NAME);
    }
    if (parent.hasProperty(REP_ACCESS_CONTROLLED_PATH)) {
      if (!PermissionUtil.checkACLPath(parent,accessControlledPath)) {
        NodeBuilder child=null;
        int idx=0;
        for (        String childName : parent.getChildNodeNames()) {
          if (childName.charAt(0) != 'c') {
            continue;
          }
          child=parent.getChildNode(childName);
          if (PermissionUtil.checkACLPath(child,accessControlledPath)) {
            break;
          }
          child=null;
          idx++;
        }
        while (child == null) {
          String name='c' + String.valueOf(idx++);
          child=parent.getChildNode(name);
          if (child.exists()) {
            child=null;
          }
 else {
            child=parent.child(name);
            child.setProperty(JCR_PRIMARYTYPE,NT_REP_PERMISSION_STORE,Type.NAME);
          }
        }
        parent=child;
        parent.setProperty(REP_ACCESS_CONTROLLED_PATH,accessControlledPath);
      }
    }
 else {
      parent.setProperty(REP_ACCESS_CONTROLLED_PATH,accessControlledPath);
    }
    updateEntries(parent,entries.get(principalName));
  }
}

Fixed version (ground truth):
void updatePermissionEntries(){
  for (  Map.Entry<String,List<AcEntry>> entry : entries.entrySet()) {
    String principalName=entry.getKey();
    NodeBuilder principalRoot=permissionRoot.child(principalName);
    if (!principalRoot.hasProperty(JCR_PRIMARYTYPE)) {
      principalRoot.setProperty(JCR_PRIMARYTYPE,NT_REP_PERMISSION_STORE,Type.NAME);
    }
    NodeBuilder parent=principalRoot.child(nodeName);
    if (!parent.hasProperty(JCR_PRIMARYTYPE)) {
      parent.setProperty(JCR_PRIMARYTYPE,NT_REP_PERMISSION_STORE,Type.NAME);
    }
    if (parent.hasProperty(REP_ACCESS_CONTROLLED_PATH)) {
      if (!PermissionUtil.checkACLPath(parent,accessControlledPath)) {
        NodeBuilder child=null;
        int idx=0;
        for (        String childName : parent.getChildNodeNames()) {
          if (childName.charAt(0) != 'c') {
            continue;
          }
          child=parent.getChildNode(childName);
          if (PermissionUtil.checkACLPath(child,accessControlledPath)) {
            break;
          }
          child=null;
          idx++;
        }
        while (child == null) {
          String name='c' + String.valueOf(idx++);
          child=parent.getChildNode(name);
          if (child.exists()) {
            child=null;
          }
 else {
            child=parent.child(name);
            child.setProperty(JCR_PRIMARYTYPE,NT_REP_PERMISSION_STORE,Type.NAME);
          }
        }
        parent=child;
        parent.setProperty(REP_ACCESS_CONTROLLED_PATH,accessControlledPath);
      }
    }
 else {
      parent.setProperty(REP_ACCESS_CONTROLLED_PATH,accessControlledPath);
    }
    updateEntries(parent,entry.getValue());
  }
}