Program: 69262
Project: 69262
Buggy source:
/** 
 * The method updates empty and null values!
 * @param re
 * @param displayName
 * @param externalRef
 * @param authors
 * @param description
 * @param objectives
 * @param requirements
 * @param credits
 * @param mainLanguage
 * @param expenditureOfWork
 * @param cycle
 * @return
 */
public RepositoryEntry setDescriptionAndName(final RepositoryEntry re,String displayName,String externalRef,String authors,String description,String objectives,String requirements,String credits,String mainLanguage,String location,String expenditureOfWork,RepositoryEntryLifecycle cycle,List<Organisation> organisations){
  RepositoryEntry reloadedRe=repositoryEntryDao.loadForUpdate(re);
  if (reloadedRe == null) {
    return null;
  }
  reloadedRe.setDisplayname(displayName);
  reloadedRe.setAuthors(authors);
  reloadedRe.setDescription(description);
  reloadedRe.setExternalRef(externalRef);
  reloadedRe.setObjectives(objectives);
  reloadedRe.setRequirements(requirements);
  reloadedRe.setCredits(credits);
  reloadedRe.setMainLanguage(mainLanguage);
  reloadedRe.setExpenditureOfWork(expenditureOfWork);
  reloadedRe.setLocation(location);
  RepositoryEntryLifecycle cycleToDelete=null;
  RepositoryEntryLifecycle currentCycle=reloadedRe.getLifecycle();
  if (currentCycle != null) {
    if (currentCycle.isPrivateCycle()) {
      if (cycle == null || !cycle.isPrivateCycle()) {
        cycleToDelete=currentCycle;
      }
    }
  }
  if (organisations != null) {
    Set<RepositoryEntryToOrganisation> currentRelations=reloadedRe.getOrganisations();
    List<RepositoryEntryToOrganisation> copyRelations=new ArrayList<>(currentRelations);
    Set<Organisation> currentOrganisations=new HashSet<>();
    for (    RepositoryEntryToOrganisation relation : copyRelations) {
      if (!organisations.contains(relation.getOrganisation())) {
        repositoryEntryToOrganisationDao.delete(relation);
        repositoryEntryRelationDao.removeRelation(relation.getOrganisation().getGroup());
      }
 else {
        currentOrganisations.add(relation.getOrganisation());
      }
    }
    for (    Organisation organisation : organisations) {
      if (!currentOrganisations.contains(organisation)) {
        RepositoryEntryToOrganisation newRelation=repositoryEntryToOrganisationDao.createRelation(organisation,reloadedRe,false);
        currentRelations.add(newRelation);
        RepositoryEntryToGroupRelation relToGroup=repositoryEntryRelationDao.createRelation(organisation.getGroup(),reloadedRe);
        reloadedRe.getGroups().add(relToGroup);
      }
    }
  }
  reloadedRe.setLifecycle(cycle);
  reloadedRe.setLastModified(new Date());
  RepositoryEntry updatedRe=dbInstance.getCurrentEntityManager().merge(reloadedRe);
  if (cycleToDelete != null) {
    dbInstance.getCurrentEntityManager().remove(cycleToDelete);
  }
  updatedRe.getStatistics().getLaunchCounter();
  if (updatedRe.getLifecycle() != null) {
    updatedRe.getLifecycle().getCreationDate();
  }
  dbInstance.commit();
  lifeIndexer.indexDocument(RepositoryEntryDocument.TYPE,updatedRe.getKey());
  autoAccessManager.grantAccess(updatedRe);
  return updatedRe;
}

Fixed version (ground truth):
/** 
 * The method updates empty and null values!
 * @param re
 * @param displayName
 * @param externalRef
 * @param authors
 * @param description
 * @param objectives
 * @param requirements
 * @param credits
 * @param mainLanguage
 * @param expenditureOfWork
 * @param cycle
 * @return
 */
public RepositoryEntry setDescriptionAndName(final RepositoryEntry re,String displayName,String externalRef,String authors,String description,String objectives,String requirements,String credits,String mainLanguage,String location,String expenditureOfWork,RepositoryEntryLifecycle cycle,List<Organisation> organisations){
  RepositoryEntry reloadedRe=repositoryEntryDao.loadForUpdate(re);
  if (reloadedRe == null) {
    return null;
  }
  reloadedRe.setDisplayname(displayName);
  reloadedRe.setAuthors(authors);
  reloadedRe.setDescription(description);
  reloadedRe.setExternalRef(externalRef);
  reloadedRe.setObjectives(objectives);
  reloadedRe.setRequirements(requirements);
  reloadedRe.setCredits(credits);
  reloadedRe.setMainLanguage(mainLanguage);
  reloadedRe.setExpenditureOfWork(expenditureOfWork);
  reloadedRe.setLocation(location);
  RepositoryEntryLifecycle cycleToDelete=null;
  RepositoryEntryLifecycle currentCycle=reloadedRe.getLifecycle();
  if (currentCycle != null) {
    if (currentCycle.isPrivateCycle()) {
      if (cycle == null || !cycle.isPrivateCycle()) {
        cycleToDelete=currentCycle;
      }
    }
  }
  if (organisations != null) {
    List<Organisation> currentOrganisationsByGroups=repositoryEntryRelationDao.getOrganisations(reloadedRe);
    for (    Organisation currentOrganisation : currentOrganisationsByGroups) {
      if (!organisations.contains(currentOrganisation)) {
        repositoryEntryRelationDao.removeRelation(currentOrganisation.getGroup(),reloadedRe);
      }
    }
    for (    Organisation organisation : organisations) {
      if (!currentOrganisationsByGroups.contains(organisation)) {
        RepositoryEntryToGroupRelation relToGroup=repositoryEntryRelationDao.createRelation(organisation.getGroup(),reloadedRe);
        reloadedRe.getGroups().add(relToGroup);
      }
    }
    Set<RepositoryEntryToOrganisation> currentRelations=reloadedRe.getOrganisations();
    List<RepositoryEntryToOrganisation> copyRelations=new ArrayList<>(currentRelations);
    List<Organisation> currentOrganisationsByRelations=new ArrayList<>();
    for (    RepositoryEntryToOrganisation relation : copyRelations) {
      if (!organisations.contains(relation.getOrganisation())) {
        repositoryEntryToOrganisationDao.delete(relation);
        currentRelations.remove(relation);
      }
 else {
        currentOrganisationsByRelations.add(relation.getOrganisation());
      }
    }
    for (    Organisation organisation : organisations) {
      if (!currentOrganisationsByRelations.contains(organisation)) {
        RepositoryEntryToOrganisation newRelation=repositoryEntryToOrganisationDao.createRelation(organisation,reloadedRe,false);
        currentRelations.add(newRelation);
      }
    }
  }
  reloadedRe.setLifecycle(cycle);
  reloadedRe.setLastModified(new Date());
  RepositoryEntry updatedRe=dbInstance.getCurrentEntityManager().merge(reloadedRe);
  if (cycleToDelete != null) {
    dbInstance.getCurrentEntityManager().remove(cycleToDelete);
  }
  updatedRe.getStatistics().getLaunchCounter();
  if (updatedRe.getLifecycle() != null) {
    updatedRe.getLifecycle().getCreationDate();
  }
  dbInstance.commit();
  lifeIndexer.indexDocument(RepositoryEntryDocument.TYPE,updatedRe.getKey());
  autoAccessManager.grantAccess(updatedRe);
  return updatedRe;
}