code: protected void checkForCyclicDependencies(AccessControlGroup group, List<AccessControlGroup> groupList) {
  
      for (AccessControlGroup inheritedGroup : group.getInherits()) {
        if (groupList.contains(inheritedGroup)) {
          StringBuilder sb = new StringBuilder("A cyclic dependency of access control groups has been detected: \n");
          for (int i = groupList.size() - 1; i >= 0; i--) {
            AccessControlGroup node = groupList.get(i);
            sb.append(node);
            if (i > 0) {
              sb.append("-->");
            }
          }
          throw new IllegalStateException(sb.toString());
        }
        groupList.add(inheritedGroup);
        checkForCyclicDependencies(inheritedGroup, groupList);
        AccessControlGroup removed = groupList.remove(groupList.size() - 1);
        assert (removed == inheritedGroup);
      }
    }
docs: Checks that the given {@link AccessControlGroup} has no cyclic {@link AccessControlGroup#getInherits() inheritance
  graph}.
  
  @param group is the {@link AccessControlGroup} to check.
  @param groupList the {@link List} of visited {@link AccessControlGroup}s used to detect cycles.