Program: 69280
Project: 69280
Buggy source:
private void doSaveChanges(){
  List<BGRightsOption> options=tableDataModel.getObjects();
  List<Group> groups=getAllBaseGroups();
  List<BGRights> currentRights=rightManager.findBGRights(groups,courseEntry.getOlatResource());
  Map<Group,BGRights> tutorToRightsMap=new HashMap<>();
  Map<Group,BGRights> participantToRightsMap=new HashMap<>();
  for (  BGRights right : currentRights) {
    if (right.getRole() == BGRightsRole.tutor) {
      tutorToRightsMap.put(right.getBaseGroup(),right);
    }
 else     if (right.getRole() == BGRightsRole.participant) {
      participantToRightsMap.put(right.getBaseGroup(),right);
    }
  }
  for (  BGRightsOption option : options) {
    List<String> newPermissions=option.getSelectedPermissions();
    BGRights rights=null;
    if (option.getRole() == BGRightsRole.tutor) {
      rights=tutorToRightsMap.get(option.getBaseGroup());
    }
 else     if (option.getRole() == BGRightsRole.participant) {
      rights=participantToRightsMap.get(option.getBaseGroup());
    }
    if (rights == null && newPermissions.isEmpty()) {
      continue;
    }
    List<String> currentPermissions=(rights == null ? Collections.<String>emptyList() : rights.getRights());
    if (newPermissions.containsAll(currentPermissions) && currentPermissions.containsAll(newPermissions)) {
      continue;
    }
    List<String> newPermissionsTmp=new ArrayList<>(newPermissions);
    newPermissionsTmp.removeAll(currentPermissions);
    for (    String newPermission : newPermissionsTmp) {
      rightManager.addBGRight(newPermission,option.getBaseGroup(),courseEntry.getOlatResource(),option.getRole());
    }
    currentPermissions.removeAll(newPermissions);
    for (    String currentPermission : currentPermissions) {
      rightManager.removeBGRight(currentPermission,option.getBaseGroup(),courseEntry.getOlatResource(),option.getRole());
    }
  }
}

Fixed version (ground truth):
private void doSaveChanges(){
  List<BGRightsRow> options=tableDataModel.getObjects();
  List<Group> groups=getAllBaseGroups();
  List<BGRights> currentRights=rightManager.findBGRights(groups,courseEntry.getOlatResource());
  Map<Group,BGRights> tutorToRightsMap=new HashMap<>();
  Map<Group,BGRights> participantToRightsMap=new HashMap<>();
  for (  BGRights right : currentRights) {
    if (right.getRole() == BGRightsRole.tutor) {
      tutorToRightsMap.put(right.getBaseGroup(),right);
    }
 else     if (right.getRole() == BGRightsRole.participant) {
      participantToRightsMap.put(right.getBaseGroup(),right);
    }
  }
  for (  BGRightsRow option : options) {
    List<String> newPermissions=option.getSelectedPermissions();
    BGRights rights=null;
    if (option.getRole() == BGRightsRole.tutor) {
      rights=tutorToRightsMap.get(option.getBaseGroup());
    }
 else     if (option.getRole() == BGRightsRole.participant) {
      rights=participantToRightsMap.get(option.getBaseGroup());
    }
    if (rights == null && newPermissions.isEmpty()) {
      continue;
    }
    List<String> currentPermissions=(rights == null ? Collections.<String>emptyList() : rights.getRights());
    if (newPermissions.containsAll(currentPermissions) && currentPermissions.containsAll(newPermissions)) {
      continue;
    }
    List<String> newPermissionsTmp=new ArrayList<>(newPermissions);
    newPermissionsTmp.removeAll(currentPermissions);
    for (    String newPermission : newPermissionsTmp) {
      rightManager.addBGRight(newPermission,option.getBaseGroup(),courseEntry.getOlatResource(),option.getRole());
    }
    currentPermissions.removeAll(newPermissions);
    for (    String currentPermission : currentPermissions) {
      rightManager.removeBGRight(currentPermission,option.getBaseGroup(),courseEntry.getOlatResource(),option.getRole());
    }
  }
}