Program: 9004
Project: 9004
Buggy source:
/** 
 * Calculate the granted permissions by evaluating the given privileges. Note, that only built-in privileges can be mapped to permissions. Any other privileges will be ignored.
 * @param bits The set of privileges present at given tree.
 * @param parentBits The privileges present on the parent tree. These arerequired in order to determine permissions that include a modification of the parent tree (add_child_nodes, remove_child_nodes).
 * @param isAllow {@code true} if the privileges are granted; {@code false}otherwise.
 * @return the resulting permissions.
 */
public static long calculatePermissions(@Nonnull PrivilegeBits bits,@Nonnull PrivilegeBits parentBits,boolean isAllow){
  long privs=bits.d.longValue();
  long parentPrivs=parentBits.d.longValue();
  long perm=Permissions.NO_PERMISSION;
  if ((privs & READ) == READ) {
    perm|=Permissions.READ;
  }
 else {
    if ((privs & READ_NODES) == READ_NODES) {
      perm|=Permissions.READ_NODE;
    }
 else     if (((privs & READ_PROPERTIES) == READ_PROPERTIES)) {
      perm|=Permissions.READ_PROPERTY;
    }
  }
  if ((privs & MODIFY_PROPERTIES) == MODIFY_PROPERTIES) {
    perm|=Permissions.SET_PROPERTY;
  }
 else {
    if ((privs & ADD_PROPERTIES) == ADD_PROPERTIES) {
      perm|=Permissions.ADD_PROPERTY;
    }
 else     if ((privs & ALTER_PROPERTIES) == ALTER_PROPERTIES) {
      perm|=Permissions.MODIFY_PROPERTY;
    }
 else     if ((privs & REMOVE_PROPERTIES) == REMOVE_PROPERTIES) {
      perm|=Permissions.REMOVE_PROPERTY;
    }
  }
  if ((parentPrivs & ADD_CHILD_NODES) == ADD_CHILD_NODES) {
    perm|=Permissions.ADD_NODE;
  }
  if (isAllow) {
    if ((parentPrivs & REMOVE_CHILD_NODES) == REMOVE_CHILD_NODES && (privs & REMOVE_NODE) == REMOVE_NODE) {
      perm|=Permissions.REMOVE_NODE;
    }
  }
 else {
    if ((parentPrivs & REMOVE_CHILD_NODES) == REMOVE_CHILD_NODES || (privs & REMOVE_NODE) == REMOVE_NODE) {
      perm|=Permissions.REMOVE_NODE;
    }
  }
  if ((parentPrivs & ADD_CHILD_NODES) == ADD_CHILD_NODES && (parentPrivs & REMOVE_CHILD_NODES) == REMOVE_CHILD_NODES) {
    perm|=Permissions.MODIFY_CHILD_NODE_COLLECTION;
  }
  if ((privs & READ_AC) == READ_AC) {
    perm|=Permissions.READ_ACCESS_CONTROL;
  }
  if ((privs & MODIFY_AC) == MODIFY_AC) {
    perm|=Permissions.MODIFY_ACCESS_CONTROL;
  }
  if ((privs & LIFECYCLE_MNGMT) == LIFECYCLE_MNGMT) {
    perm|=Permissions.LIFECYCLE_MANAGEMENT;
  }
  if ((privs & LOCK_MNGMT) == LOCK_MNGMT) {
    perm|=Permissions.LOCK_MANAGEMENT;
  }
  if ((privs & NODE_TYPE_MNGMT) == NODE_TYPE_MNGMT) {
    perm|=Permissions.NODE_TYPE_MANAGEMENT;
  }
  if ((privs & RETENTION_MNGMT) == RETENTION_MNGMT) {
    perm|=Permissions.RETENTION_MANAGEMENT;
  }
  if ((privs & VERSION_MNGMT) == VERSION_MNGMT) {
    perm|=Permissions.VERSION_MANAGEMENT;
  }
  if ((privs & WORKSPACE_MNGMT) == WORKSPACE_MNGMT) {
    perm|=Permissions.WORKSPACE_MANAGEMENT;
  }
  if ((privs & NODE_TYPE_DEF_MNGMT) == NODE_TYPE_DEF_MNGMT) {
    perm|=Permissions.NODE_TYPE_DEFINITION_MANAGEMENT;
  }
  if ((privs & NAMESPACE_MNGMT) == NAMESPACE_MNGMT) {
    perm|=Permissions.NAMESPACE_MANAGEMENT;
  }
  if ((privs & PRIVILEGE_MNGMT) == PRIVILEGE_MNGMT) {
    perm|=Permissions.PRIVILEGE_MANAGEMENT;
  }
  if ((privs & USER_MNGMT) == USER_MNGMT) {
    perm|=Permissions.USER_MANAGEMENT;
  }
  return perm;
}

Fixed version (ground truth):
/** 
 * Calculate the granted permissions by evaluating the given privileges. Note, that only built-in privileges can be mapped to permissions. Any other privileges will be ignored.
 * @param bits The set of privileges present at given tree.
 * @param parentBits The privileges present on the parent tree. These arerequired in order to determine permissions that include a modification of the parent tree (add_child_nodes, remove_child_nodes).
 * @param isAllow {@code true} if the privileges are granted; {@code false}otherwise.
 * @return the resulting permissions.
 */
public static long calculatePermissions(@Nonnull PrivilegeBits bits,@Nonnull PrivilegeBits parentBits,boolean isAllow){
  long privs=bits.d.longValue();
  long parentPrivs=parentBits.d.longValue();
  long perm=Permissions.NO_PERMISSION;
  if ((privs & READ) == READ) {
    perm|=Permissions.READ;
  }
 else {
    if ((privs & READ_NODES) == READ_NODES) {
      perm|=Permissions.READ_NODE;
    }
 else     if (((privs & READ_PROPERTIES) == READ_PROPERTIES)) {
      perm|=Permissions.READ_PROPERTY;
    }
  }
  if ((privs & MODIFY_PROPERTIES) == MODIFY_PROPERTIES) {
    perm|=Permissions.SET_PROPERTY;
  }
 else {
    if ((privs & ADD_PROPERTIES) == ADD_PROPERTIES) {
      perm|=Permissions.ADD_PROPERTY;
    }
    if ((privs & ALTER_PROPERTIES) == ALTER_PROPERTIES) {
      perm|=Permissions.MODIFY_PROPERTY;
    }
    if ((privs & REMOVE_PROPERTIES) == REMOVE_PROPERTIES) {
      perm|=Permissions.REMOVE_PROPERTY;
    }
  }
  if ((parentPrivs & ADD_CHILD_NODES) == ADD_CHILD_NODES) {
    perm|=Permissions.ADD_NODE;
  }
  if (isAllow) {
    if ((parentPrivs & REMOVE_CHILD_NODES) == REMOVE_CHILD_NODES && (privs & REMOVE_NODE) == REMOVE_NODE) {
      perm|=Permissions.REMOVE_NODE;
    }
  }
 else {
    if ((parentPrivs & REMOVE_CHILD_NODES) == REMOVE_CHILD_NODES || (privs & REMOVE_NODE) == REMOVE_NODE) {
      perm|=Permissions.REMOVE_NODE;
    }
  }
  if ((parentPrivs & ADD_CHILD_NODES) == ADD_CHILD_NODES && (parentPrivs & REMOVE_CHILD_NODES) == REMOVE_CHILD_NODES) {
    perm|=Permissions.MODIFY_CHILD_NODE_COLLECTION;
  }
  if ((privs & READ_AC) == READ_AC) {
    perm|=Permissions.READ_ACCESS_CONTROL;
  }
  if ((privs & MODIFY_AC) == MODIFY_AC) {
    perm|=Permissions.MODIFY_ACCESS_CONTROL;
  }
  if ((privs & LIFECYCLE_MNGMT) == LIFECYCLE_MNGMT) {
    perm|=Permissions.LIFECYCLE_MANAGEMENT;
  }
  if ((privs & LOCK_MNGMT) == LOCK_MNGMT) {
    perm|=Permissions.LOCK_MANAGEMENT;
  }
  if ((privs & NODE_TYPE_MNGMT) == NODE_TYPE_MNGMT) {
    perm|=Permissions.NODE_TYPE_MANAGEMENT;
  }
  if ((privs & RETENTION_MNGMT) == RETENTION_MNGMT) {
    perm|=Permissions.RETENTION_MANAGEMENT;
  }
  if ((privs & VERSION_MNGMT) == VERSION_MNGMT) {
    perm|=Permissions.VERSION_MANAGEMENT;
  }
  if ((privs & WORKSPACE_MNGMT) == WORKSPACE_MNGMT) {
    perm|=Permissions.WORKSPACE_MANAGEMENT;
  }
  if ((privs & NODE_TYPE_DEF_MNGMT) == NODE_TYPE_DEF_MNGMT) {
    perm|=Permissions.NODE_TYPE_DEFINITION_MANAGEMENT;
  }
  if ((privs & NAMESPACE_MNGMT) == NAMESPACE_MNGMT) {
    perm|=Permissions.NAMESPACE_MANAGEMENT;
  }
  if ((privs & PRIVILEGE_MNGMT) == PRIVILEGE_MNGMT) {
    perm|=Permissions.PRIVILEGE_MANAGEMENT;
  }
  if ((privs & USER_MNGMT) == USER_MNGMT) {
    perm|=Permissions.USER_MANAGEMENT;
  }
  return perm;
}