Program: 35666
Project: 35666
Buggy source:
@Override public void update(User user,Object entity,PropertyMap changes){
  ProjectModel model=null;
  if (projectModel != null) {
    model=em.find(ProjectModel.class,new Integer(projectModel.getId()).longValue());
  }
  if (model != null) {
    if (changes.get(AdminUtil.PROP_PM_NAME) != null)     model.setName((String)changes.get(AdminUtil.PROP_PM_NAME));
    if (changes.get(AdminUtil.PROP_PM_STATUS) != null)     model.setStatus((ProjectModelStatus)changes.get(AdminUtil.PROP_PM_STATUS));
    if (changes.get(AdminUtil.PROP_PM_USE) != null) {
      List<ProjectModelVisibility> visibilities=model.getVisibilities();
      for (      ProjectModelVisibility v : visibilities) {
        if (user.getOrganization().equals(v.getOrganization())) {
          v.setType((ProjectModelType)changes.get(AdminUtil.PROP_PM_USE));
          em.merge(v);
        }
      }
    }
    model=em.merge(model);
    if (changes.get(AdminUtil.PROP_LOG_FRAME) != null && (Boolean)changes.get(AdminUtil.PROP_LOG_FRAME)) {
      LogFrameModel logFrameModel=null;
      if (model.getLogFrameModel() != null) {
        logFrameModel=em.find(LogFrameModel.class,model.getLogFrameModel().getId());
      }
 else {
        logFrameModel=new LogFrameModel();
        logFrameModel.setProjectModel(model);
      }
      if (changes.get(AdminUtil.PROP_LOG_FRAME_NAME) != null)       log_frame_name=(String)changes.get(AdminUtil.PROP_LOG_FRAME_NAME);
      if (changes.get(AdminUtil.PROP_OBJ_MAX) != null)       objectives_max=(Integer)changes.get(AdminUtil.PROP_OBJ_MAX);
      if (changes.get(AdminUtil.PROP_OBJ_MAX_PER_GROUP) != null)       objectives_max_per_group=(Integer)changes.get(AdminUtil.PROP_OBJ_MAX_PER_GROUP);
      if (changes.get(AdminUtil.PROP_OBJ_ENABLE_GROUPS) != null)       objectives_enable_groups=(Boolean)changes.get(AdminUtil.PROP_OBJ_ENABLE_GROUPS);
      if (changes.get(AdminUtil.PROP_OBJ_MAX_GROUPS) != null)       objectives_max_groups=(Integer)changes.get(AdminUtil.PROP_OBJ_MAX_GROUPS);
      if (changes.get(AdminUtil.PROP_A_MAX) != null)       activities_max=(Integer)changes.get(AdminUtil.PROP_A_MAX);
      if (changes.get(AdminUtil.PROP_A_ENABLE_GROUPS) != null)       activities_enable_groups=(Boolean)changes.get(AdminUtil.PROP_A_ENABLE_GROUPS);
      if (changes.get(AdminUtil.PROP_A_MAX_PER_RESULT) != null)       activities_max_per_result=(Integer)changes.get(AdminUtil.PROP_A_MAX_PER_RESULT);
      if (changes.get(AdminUtil.PROP_A_MAX_GROUPS) != null)       activities_max_groups=(Integer)changes.get(AdminUtil.PROP_A_MAX_GROUPS);
      if (changes.get(AdminUtil.PROP_A_MAX_PER_GROUP) != null)       activities_max_per_group=(Integer)changes.get(AdminUtil.PROP_A_MAX_PER_GROUP);
      if (changes.get(AdminUtil.PROP_R_MAX) != null)       results_max=(Integer)changes.get(AdminUtil.PROP_R_MAX);
      if (changes.get(AdminUtil.PROP_R_ENABLE_GROUPS) != null)       results_enable_groups=(Boolean)changes.get(AdminUtil.PROP_R_ENABLE_GROUPS);
      if (changes.get(AdminUtil.PROP_R_MAX_PER_OBJ) != null)       results_max_per_obj=(Integer)changes.get(AdminUtil.PROP_R_MAX_PER_OBJ);
      if (changes.get(AdminUtil.PROP_R_MAX_GROUPS) != null)       results_max_groups=(Integer)changes.get(AdminUtil.PROP_R_MAX_GROUPS);
      if (changes.get(AdminUtil.PROP_R_MAX_PER_GROUP) != null)       results_max_per_group=(Integer)changes.get(AdminUtil.PROP_R_MAX_PER_GROUP);
      if (changes.get(AdminUtil.PROP_P_MAX) != null)       prerequisites_max=(Integer)changes.get(AdminUtil.PROP_P_MAX);
      if (changes.get(AdminUtil.PROP_P_ENABLE_GROUPS) != null)       prerequisites_enable_groups=(Boolean)changes.get(AdminUtil.PROP_P_ENABLE_GROUPS);
      if (changes.get(AdminUtil.PROP_P_MAX_GROUPS) != null)       prerequisites_max_groups=(Integer)changes.get(AdminUtil.PROP_P_MAX_GROUPS);
      if (changes.get(AdminUtil.PROP_P_MAX_PER_GROUP) != null)       prerequisites_max_per_group=(Integer)changes.get(AdminUtil.PROP_P_MAX_PER_GROUP);
      logFrameModel.setName(log_frame_name);
      logFrameModel.setActivitiesGroupsMax(activities_max_groups);
      logFrameModel.setActivitiesMax(activities_max);
      logFrameModel.setActivitiesPerExpectedResultMax(activities_max_per_result);
      logFrameModel.setActivitiesPerGroupMax(activities_max_per_group);
      logFrameModel.setEnableActivitiesGroups(activities_enable_groups);
      logFrameModel.setEnableExpectedResultsGroups(results_enable_groups);
      logFrameModel.setExpectedResultsGroupsMax(results_max_groups);
      logFrameModel.setExpectedResultsMax(results_max);
      logFrameModel.setExpectedResultsPerGroupMax(results_max_per_group);
      logFrameModel.setExpectedResultsPerSpecificObjectiveMax(results_max_per_obj);
      logFrameModel.setSpecificObjectivesGroupsMax(objectives_max_groups);
      logFrameModel.setEnableSpecificObjectivesGroups(objectives_enable_groups);
      logFrameModel.setSpecificObjectivesMax(objectives_max);
      logFrameModel.setSpecificObjectivesPerGroupMax(objectives_max_per_group);
      logFrameModel.setPrerequisitesGroupsMax(prerequisites_max_groups);
      logFrameModel.setEnablePrerequisitesGroups(prerequisites_enable_groups);
      logFrameModel.setPrerequisitesMax(prerequisites_max);
      logFrameModel.setPrerequisitesPerGroupMax(prerequisites_max_per_group);
      if (model.getLogFrameModel() != null) {
        logFrameModel=em.merge(logFrameModel);
      }
 else {
        em.persist(logFrameModel);
      }
      modelToUpdate=model;
      modelToUpdate.setLogFrameModel(logFrameModel);
    }
    if (changes.get(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT) != null) {
      ModelUtil.persistFlexibleElement(em,mapper,changes,model);
      modelToUpdate=em.find(ProjectModel.class,model.getId());
    }
    final PhaseModelDTO phaseDTOToSave=(PhaseModelDTO)changes.get(AdminUtil.PROP_PHASE_MODEL);
    final Integer displayOrder=(Integer)changes.get(AdminUtil.PROP_PHASE_ORDER);
    final Boolean root=(Boolean)changes.get(AdminUtil.PROP_PHASE_ROOT);
    final Integer numRows=(Integer)changes.get(AdminUtil.PROP_PHASE_ROWS);
    final String guide=(String)changes.get(AdminUtil.PROP_PHASE_GUIDE);
    PhaseModel phaseToSave=new PhaseModel();
    if (phaseDTOToSave != null) {
      phaseToSave.setName(phaseDTOToSave.getName());
      if (displayOrder != null)       phaseToSave.setDisplayOrder(displayOrder);
      if (guide != null && !guide.isEmpty())       phaseToSave.setGuide(guide);
      for (      PhaseModelDTO sucDTO : phaseDTOToSave.getSuccessorsDTO()) {
        if (sucDTO.getId() != 0) {
          PhaseModel suc=em.find(PhaseModel.class,Long.valueOf(String.valueOf(sucDTO.getId())));
          phaseToSave.getSuccessors().add(suc);
        }
      }
      PhaseModel phaseFound=null;
      for (      PhaseModel phase : model.getPhases()) {
        if (phaseDTOToSave.getId() == phase.getId()) {
          phaseFound=phase;
        }
      }
      if (phaseFound != null) {
        phaseFound.setName(phaseToSave.getName());
        phaseFound.setSuccessors(phaseToSave.getSuccessors());
        if (numRows != null)         phaseFound.getLayout().setRowsCount(numRows);
        if (displayOrder != null)         phaseFound.setDisplayOrder(displayOrder);
        if (guide != null && !guide.isEmpty())         phaseFound.setGuide(guide);
        phaseToSave=em.merge(phaseFound);
      }
 else {
        phaseToSave.setParentProjectModel(model);
        Layout phaseLayout=new Layout();
        phaseLayout.setColumnsCount(1);
        if (numRows != null)         phaseLayout.setRowsCount(numRows);
 else         phaseLayout.setRowsCount(4);
        LayoutGroup phaseGroup=new LayoutGroup();
        phaseGroup.setTitle(phaseToSave.getName() + "String_Node_Str");
        phaseGroup.setColumn(0);
        phaseGroup.setRow(0);
        phaseGroup.setParentLayout(phaseLayout);
        List<LayoutGroup> phaseGroups=new ArrayList<LayoutGroup>();
        phaseGroups.add(phaseGroup);
        phaseLayout.setGroups(phaseGroups);
        phaseToSave.setLayout(phaseLayout);
        em.persist(phaseToSave);
      }
      model.addPhase(phaseToSave);
      if (root != null && root)       model.setRootPhase(phaseToSave);
 else       if (root != null && !root && phaseFound != null && model.getRootPhase().getId() == phaseFound.getId())       model.setRootPhase(null);
      modelToUpdate=em.merge(model);
    }
  }
}

Fixed version (ground truth):
@Override public void update(User user,Object entity,PropertyMap changes){
  ProjectModel model=null;
  if (projectModel != null) {
    model=em.find(ProjectModel.class,new Integer(projectModel.getId()).longValue());
  }
  if (model != null) {
    if (changes.get(AdminUtil.PROP_PM_NAME) != null)     model.setName((String)changes.get(AdminUtil.PROP_PM_NAME));
    if (changes.get(AdminUtil.PROP_PM_STATUS) != null)     model.setStatus((ProjectModelStatus)changes.get(AdminUtil.PROP_PM_STATUS));
    if (changes.get(AdminUtil.PROP_PM_USE) != null) {
      List<ProjectModelVisibility> visibilities=model.getVisibilities();
      for (      ProjectModelVisibility v : visibilities) {
        if (user.getOrganization().equals(v.getOrganization())) {
          v.setType((ProjectModelType)changes.get(AdminUtil.PROP_PM_USE));
          em.merge(v);
        }
      }
    }
    model=em.merge(model);
    if (changes.get(AdminUtil.PROP_LOG_FRAME) != null && (Boolean)changes.get(AdminUtil.PROP_LOG_FRAME)) {
      LogFrameModel logFrameModel=null;
      if (model.getLogFrameModel() != null) {
        logFrameModel=em.find(LogFrameModel.class,model.getLogFrameModel().getId());
      }
 else {
        logFrameModel=new LogFrameModel();
        logFrameModel.setProjectModel(model);
      }
      if (changes.get(AdminUtil.PROP_LOG_FRAME_NAME) != null)       log_frame_name=(String)changes.get(AdminUtil.PROP_LOG_FRAME_NAME);
      if (changes.get(AdminUtil.PROP_OBJ_MAX) != null)       objectives_max=(Integer)changes.get(AdminUtil.PROP_OBJ_MAX);
      if (changes.get(AdminUtil.PROP_OBJ_MAX_PER_GROUP) != null)       objectives_max_per_group=(Integer)changes.get(AdminUtil.PROP_OBJ_MAX_PER_GROUP);
      if (changes.get(AdminUtil.PROP_OBJ_ENABLE_GROUPS) != null)       objectives_enable_groups=(Boolean)changes.get(AdminUtil.PROP_OBJ_ENABLE_GROUPS);
      if (changes.get(AdminUtil.PROP_OBJ_MAX_GROUPS) != null)       objectives_max_groups=(Integer)changes.get(AdminUtil.PROP_OBJ_MAX_GROUPS);
      if (changes.get(AdminUtil.PROP_A_MAX) != null)       activities_max=(Integer)changes.get(AdminUtil.PROP_A_MAX);
      if (changes.get(AdminUtil.PROP_A_ENABLE_GROUPS) != null)       activities_enable_groups=(Boolean)changes.get(AdminUtil.PROP_A_ENABLE_GROUPS);
      if (changes.get(AdminUtil.PROP_A_MAX_PER_RESULT) != null)       activities_max_per_result=(Integer)changes.get(AdminUtil.PROP_A_MAX_PER_RESULT);
      if (changes.get(AdminUtil.PROP_A_MAX_GROUPS) != null)       activities_max_groups=(Integer)changes.get(AdminUtil.PROP_A_MAX_GROUPS);
      if (changes.get(AdminUtil.PROP_A_MAX_PER_GROUP) != null)       activities_max_per_group=(Integer)changes.get(AdminUtil.PROP_A_MAX_PER_GROUP);
      if (changes.get(AdminUtil.PROP_R_MAX) != null)       results_max=(Integer)changes.get(AdminUtil.PROP_R_MAX);
      if (changes.get(AdminUtil.PROP_R_ENABLE_GROUPS) != null)       results_enable_groups=(Boolean)changes.get(AdminUtil.PROP_R_ENABLE_GROUPS);
      if (changes.get(AdminUtil.PROP_R_MAX_PER_OBJ) != null)       results_max_per_obj=(Integer)changes.get(AdminUtil.PROP_R_MAX_PER_OBJ);
      if (changes.get(AdminUtil.PROP_R_MAX_GROUPS) != null)       results_max_groups=(Integer)changes.get(AdminUtil.PROP_R_MAX_GROUPS);
      if (changes.get(AdminUtil.PROP_R_MAX_PER_GROUP) != null)       results_max_per_group=(Integer)changes.get(AdminUtil.PROP_R_MAX_PER_GROUP);
      if (changes.get(AdminUtil.PROP_P_MAX) != null)       prerequisites_max=(Integer)changes.get(AdminUtil.PROP_P_MAX);
      if (changes.get(AdminUtil.PROP_P_ENABLE_GROUPS) != null)       prerequisites_enable_groups=(Boolean)changes.get(AdminUtil.PROP_P_ENABLE_GROUPS);
      if (changes.get(AdminUtil.PROP_P_MAX_GROUPS) != null)       prerequisites_max_groups=(Integer)changes.get(AdminUtil.PROP_P_MAX_GROUPS);
      if (changes.get(AdminUtil.PROP_P_MAX_PER_GROUP) != null)       prerequisites_max_per_group=(Integer)changes.get(AdminUtil.PROP_P_MAX_PER_GROUP);
      logFrameModel.setName(log_frame_name);
      logFrameModel.setActivitiesGroupsMax(activities_max_groups);
      logFrameModel.setActivitiesMax(activities_max);
      logFrameModel.setActivitiesPerExpectedResultMax(activities_max_per_result);
      logFrameModel.setActivitiesPerGroupMax(activities_max_per_group);
      logFrameModel.setEnableActivitiesGroups(activities_enable_groups);
      logFrameModel.setEnableExpectedResultsGroups(results_enable_groups);
      logFrameModel.setExpectedResultsGroupsMax(results_max_groups);
      logFrameModel.setExpectedResultsMax(results_max);
      logFrameModel.setExpectedResultsPerGroupMax(results_max_per_group);
      logFrameModel.setExpectedResultsPerSpecificObjectiveMax(results_max_per_obj);
      logFrameModel.setSpecificObjectivesGroupsMax(objectives_max_groups);
      logFrameModel.setEnableSpecificObjectivesGroups(objectives_enable_groups);
      logFrameModel.setSpecificObjectivesMax(objectives_max);
      logFrameModel.setSpecificObjectivesPerGroupMax(objectives_max_per_group);
      logFrameModel.setPrerequisitesGroupsMax(prerequisites_max_groups);
      logFrameModel.setEnablePrerequisitesGroups(prerequisites_enable_groups);
      logFrameModel.setPrerequisitesMax(prerequisites_max);
      logFrameModel.setPrerequisitesPerGroupMax(prerequisites_max_per_group);
      if (model.getLogFrameModel() != null) {
        logFrameModel=em.merge(logFrameModel);
      }
 else {
        em.persist(logFrameModel);
      }
      modelToUpdate=model;
      modelToUpdate.setLogFrameModel(logFrameModel);
    }
    if (changes.get(AdminUtil.PROP_FX_FLEXIBLE_ELEMENT) != null) {
      ModelUtil.persistFlexibleElement(em,mapper,changes,model);
      modelToUpdate=em.find(ProjectModel.class,model.getId());
    }
    final PhaseModelDTO phaseDTOToSave=(PhaseModelDTO)changes.get(AdminUtil.PROP_PHASE_MODEL);
    final Integer displayOrder=(Integer)changes.get(AdminUtil.PROP_PHASE_ORDER);
    final Boolean root=(Boolean)changes.get(AdminUtil.PROP_PHASE_ROOT);
    final Integer numRows=(Integer)changes.get(AdminUtil.PROP_PHASE_ROWS);
    final String guide=(String)changes.get(AdminUtil.PROP_PHASE_GUIDE);
    PhaseModel phaseToSave=new PhaseModel();
    if (phaseDTOToSave != null) {
      phaseToSave.setName(phaseDTOToSave.getName());
      if (displayOrder != null)       phaseToSave.setDisplayOrder(displayOrder);
      if (guide != null && !guide.isEmpty())       phaseToSave.setGuide(guide);
      for (      PhaseModelDTO sucDTO : phaseDTOToSave.getSuccessorsDTO()) {
        if (sucDTO.getId() != 0) {
          PhaseModel suc=em.find(PhaseModel.class,Long.valueOf(String.valueOf(sucDTO.getId())));
          phaseToSave.getSuccessors().add(suc);
        }
      }
      PhaseModel phaseFound=null;
      for (      PhaseModel phase : model.getPhases()) {
        if (phaseDTOToSave.getId() == phase.getId()) {
          phaseFound=phase;
        }
      }
      if (phaseFound != null) {
        phaseFound.setName(phaseToSave.getName());
        phaseFound.setSuccessors(phaseToSave.getSuccessors());
        if (numRows != null)         phaseFound.getLayout().setRowsCount(numRows);
        if (displayOrder != null)         phaseFound.setDisplayOrder(displayOrder);
        if (guide != null && !guide.isEmpty())         phaseFound.setGuide(guide);
        phaseToSave=em.merge(phaseFound);
      }
 else {
        phaseToSave.setParentProjectModel(model);
        Layout phaseLayout=new Layout();
        phaseLayout.setColumnsCount(1);
        if (numRows != null)         phaseLayout.setRowsCount(numRows);
 else         phaseLayout.setRowsCount(1);
        LayoutGroup phaseGroup=new LayoutGroup();
        phaseGroup.setTitle(phaseToSave.getName() + "String_Node_Str");
        phaseGroup.setColumn(0);
        phaseGroup.setRow(0);
        phaseGroup.setParentLayout(phaseLayout);
        List<LayoutGroup> phaseGroups=new ArrayList<LayoutGroup>();
        phaseGroups.add(phaseGroup);
        phaseLayout.setGroups(phaseGroups);
        phaseToSave.setLayout(phaseLayout);
        em.persist(phaseToSave);
      }
      model.addPhase(phaseToSave);
      if (root != null && root)       model.setRootPhase(phaseToSave);
 else       if (root != null && !root && phaseFound != null && model.getRootPhase().getId() == phaseFound.getId())       model.setRootPhase(null);
      modelToUpdate=em.merge(model);
    }
  }
}