Program: 69263
Project: 69263
Buggy source:
private void initFormRoles(FormItemContainer formLayout,Organisation organisation){
  boolean admin=managerRoles.hasRoleInParentLine(organisation,OrganisationRoles.administrator) || managerRoles.hasRoleInParentLine(organisation,OrganisationRoles.rolesmanager);
  boolean userManager=managerRoles.hasRoleInParentLine(organisation,OrganisationRoles.usermanager);
  List<String> roleKeys=new ArrayList<>();
  List<String> roleValues=new ArrayList<>();
  roleKeys.add(OrganisationRoles.invitee.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.user.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.author.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.usermanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.rolesmanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.groupmanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.poolmanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.curriculummanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.lecturemanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.qualitymanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.linemanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.principal.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.administrator.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.learnresourcemanager.name());
  roleValues.add(translate("String_Node_Str"));
  MultipleSelectionElement rolesEl=uifactory.addCheckboxesHorizontal("String_Node_Str" + (++counter),"String_Node_Str",formLayout,roleKeys.toArray(new String[roleKeys.size()]),roleValues.toArray(new String[roleValues.size()]));
  if (organisations.size() > 1 || !organisation.getIdentifier().equals(OrganisationService.DEFAULT_ORGANISATION_IDENTIFIER)) {
    rolesEl.setLabel("String_Node_Str",new String[]{organisation.getDisplayName()});
  }
  rolesEl.setUserObject(new RolesElement(roleKeys,organisation,rolesEl));
  if (admin) {
    rolesEl.setEnabled(new HashSet<>(roleKeys),true);
  }
 else   if (userManager) {
    Set<String> enabled=new HashSet<>();
    enabled.add(OrganisationRoles.invitee.name());
    enabled.add(OrganisationRoles.user.name());
    enabled.add(OrganisationRoles.author.name());
    rolesEl.setEnabled(enabled,true);
    Set<String> disabled=new HashSet<>(roleKeys);
    disabled.removeAll(enabled);
    rolesEl.setEnabled(disabled,false);
  }
 else {
    rolesEl.setEnabled(new HashSet<>(roleKeys),false);
  }
  rolesEls.add(rolesEl);
}

Fixed version (ground truth):
private void initFormRoles(FormItemContainer formLayout,Organisation organisation){
  boolean admin=managerRoles.hasRoleInParentLine(organisation,OrganisationRoles.administrator) || managerRoles.hasRoleInParentLine(organisation,OrganisationRoles.rolesmanager);
  boolean userManager=managerRoles.hasRoleInParentLine(organisation,OrganisationRoles.usermanager);
  List<String> roleKeys=new ArrayList<>();
  List<String> roleValues=new ArrayList<>();
  roleKeys.add(OrganisationRoles.invitee.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.user.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.author.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.usermanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.rolesmanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.groupmanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.poolmanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.curriculummanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.lecturemanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.qualitymanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.linemanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.learnresourcemanager.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.principal.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.administrator.name());
  roleValues.add(translate("String_Node_Str"));
  roleKeys.add(OrganisationRoles.sysadmin.name());
  roleValues.add(translate("String_Node_Str"));
  MultipleSelectionElement rolesEl=uifactory.addCheckboxesHorizontal("String_Node_Str" + (++counter),"String_Node_Str",formLayout,roleKeys.toArray(new String[roleKeys.size()]),roleValues.toArray(new String[roleValues.size()]));
  if (organisations.size() > 1 || !organisation.getIdentifier().equals(OrganisationService.DEFAULT_ORGANISATION_IDENTIFIER)) {
    rolesEl.setLabel("String_Node_Str",new String[]{organisation.getDisplayName()});
  }
  rolesEl.setUserObject(new RolesElement(roleKeys,organisation,rolesEl));
  if (admin) {
    rolesEl.setEnabled(new HashSet<>(roleKeys),true);
  }
 else   if (userManager) {
    Set<String> enabled=new HashSet<>();
    enabled.add(OrganisationRoles.invitee.name());
    enabled.add(OrganisationRoles.user.name());
    enabled.add(OrganisationRoles.author.name());
    rolesEl.setEnabled(enabled,true);
    Set<String> disabled=new HashSet<>(roleKeys);
    disabled.removeAll(enabled);
    rolesEl.setEnabled(disabled,false);
  }
 else {
    rolesEl.setEnabled(new HashSet<>(roleKeys),false);
  }
  rolesEls.add(rolesEl);
}