Program: 115220
Project: 115220
Buggy source:
public List<EventCRFBean> fetchEventCRFBeans(ODMContainer odmContainer,UserAccountBean ub,StudyEventBean studyEventBean){
  ArrayList<EventCRFBean> eventCRFBeans=new ArrayList<EventCRFBean>();
  ArrayList<Integer> eventCRFBeanIds=new ArrayList<Integer>();
  EventCRFDAO eventCrfDAO=new EventCRFDAO(ds);
  StudySubjectDAO studySubjectDAO=new StudySubjectDAO(ds);
  StudyEventDefinitionDAO studyEventDefinitionDAO=new StudyEventDefinitionDAO(ds);
  StudyDAO studyDAO=new StudyDAO(ds);
  StudyEventDAO studyEventDAO=new StudyEventDAO(ds);
  String studyOID=odmContainer.getCrfDataPostImportContainer().getStudyOID();
  StudyBean studyBean=studyDAO.findByOid(studyOID);
  ArrayList<SubjectDataBean> subjectDataBeans=odmContainer.getCrfDataPostImportContainer().getSubjectData();
  for (  SubjectDataBean subjectDataBean : subjectDataBeans) {
    ArrayList<StudyEventDataBean> studyEventDataBeans=subjectDataBean.getStudyEventData();
    StudySubjectBean studySubjectBean=studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(),studyBean.getId());
    for (    StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
      ArrayList<FormDataBean> formDataBeans=studyEventDataBean.getFormData();
      String sampleOrdinal=studyEventDataBean.getStudyEventRepeatKey() == null ? "String_Node_Str" : studyEventDataBean.getStudyEventRepeatKey();
      StudyEventDefinitionBean studyEventDefinitionBean=studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(),studyBean.getId(),studyBean.getParentStudyId());
      logger.info("String_Node_Str" + studyEventDefinitionBean.getName() + "String_Node_Str"+ studySubjectBean.getName());
      for (      FormDataBean formDataBean : formDataBeans) {
        CRFVersionDAO crfVersionDAO=new CRFVersionDAO(ds);
        ArrayList<CRFVersionBean> crfVersionBeans=crfVersionDAO.findAllByOid(formDataBean.getFormOID());
        for (        CRFVersionBean crfVersionBean : crfVersionBeans) {
          System.out.println("String_Node_Str" + studySubjectBean.getId() + "String_Node_Str"+ studyEventDefinitionBean.getId()+ "String_Node_Str"+ sampleOrdinal);
          if (studyEventBean == null) {
            studyEventBean=(StudyEventBean)studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(),studyEventDefinitionBean.getId(),Integer.parseInt(sampleOrdinal));
          }
          ArrayList<EventCRFBean> eventCrfBeans=eventCrfDAO.findByEventSubjectVersion(studyEventBean,studySubjectBean,crfVersionBean);
          if (eventCrfBeans.isEmpty()) {
            logger.debug("String_Node_Str" + studyEventBean.getId() + "String_Node_Str"+ studyEventBean.getLocation());
            if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) {
              EventCRFBean newEventCrfBean=new EventCRFBean();
              newEventCrfBean.setStudyEventId(studyEventBean.getId());
              newEventCrfBean.setStudySubjectId(studySubjectBean.getId());
              newEventCrfBean.setCRFVersionId(crfVersionBean.getId());
              newEventCrfBean.setDateInterviewed(new Date());
              newEventCrfBean.setOwner(ub);
              newEventCrfBean.setInterviewerName(ub.getName());
              newEventCrfBean.setCompletionStatusId(1);
              newEventCrfBean.setStatus(Status.AVAILABLE);
              newEventCrfBean.setStage(DataEntryStage.INITIAL_DATA_ENTRY);
              newEventCrfBean=(EventCRFBean)eventCrfDAO.create(newEventCrfBean);
              eventCrfBeans.add(newEventCrfBean);
              logger.debug("String_Node_Str");
            }
          }
 else {
          }
          for (          EventCRFBean ecb : eventCrfBeans) {
            Integer ecbId=new Integer(ecb.getId());
            if (!eventCRFBeanIds.contains(ecbId)) {
              eventCRFBeans.add(ecb);
              eventCRFBeanIds.add(ecbId);
            }
          }
        }
      }
    }
  }
  return eventCRFBeans;
}

Fixed version (ground truth):
public List<EventCRFBean> fetchEventCRFBeans(ODMContainer odmContainer,UserAccountBean ub,StudyEventBean studyEventBean){
  ArrayList<EventCRFBean> eventCRFBeans=new ArrayList<EventCRFBean>();
  ArrayList<Integer> eventCRFBeanIds=new ArrayList<Integer>();
  EventCRFDAO eventCrfDAO=new EventCRFDAO(ds);
  StudySubjectDAO studySubjectDAO=new StudySubjectDAO(ds);
  StudyEventDefinitionDAO studyEventDefinitionDAO=new StudyEventDefinitionDAO(ds);
  StudyDAO studyDAO=new StudyDAO(ds);
  StudyEventDAO studyEventDAO=new StudyEventDAO(ds);
  String studyOID=odmContainer.getCrfDataPostImportContainer().getStudyOID();
  StudyBean studyBean=studyDAO.findByOid(studyOID);
  ArrayList<SubjectDataBean> subjectDataBeans=odmContainer.getCrfDataPostImportContainer().getSubjectData();
  for (  SubjectDataBean subjectDataBean : subjectDataBeans) {
    ArrayList<StudyEventDataBean> studyEventDataBeans=subjectDataBean.getStudyEventData();
    StudySubjectBean studySubjectBean=studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(),studyBean.getId());
    for (    StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
      ArrayList<FormDataBean> formDataBeans=studyEventDataBean.getFormData();
      StudyEventDefinitionBean studyEventDefinitionBean=studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(),studyBean.getId(),studyBean.getParentStudyId());
      logger.info("String_Node_Str" + studyEventDefinitionBean.getName() + "String_Node_Str"+ studySubjectBean.getName());
      int ordinal=studyEventDAO.getMaxSampleOrdinal(studyEventDefinitionBean,studySubjectBean);
      String sampleOrdinal=studyEventDataBean.getStudyEventRepeatKey() == null ? new Integer(ordinal).toString() : studyEventDataBean.getStudyEventRepeatKey();
      for (      FormDataBean formDataBean : formDataBeans) {
        CRFVersionDAO crfVersionDAO=new CRFVersionDAO(ds);
        ArrayList<CRFVersionBean> crfVersionBeans=crfVersionDAO.findAllByOid(formDataBean.getFormOID());
        for (        CRFVersionBean crfVersionBean : crfVersionBeans) {
          System.out.println("String_Node_Str" + studySubjectBean.getId() + "String_Node_Str"+ studyEventDefinitionBean.getId()+ "String_Node_Str"+ sampleOrdinal);
          if (studyEventBean == null) {
            studyEventBean=(StudyEventBean)studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(),studyEventDefinitionBean.getId(),Integer.parseInt(sampleOrdinal));
            System.out.println("String_Node_Str");
          }
          ArrayList<EventCRFBean> eventCrfBeans=eventCrfDAO.findByEventSubjectVersion(studyEventBean,studySubjectBean,crfVersionBean);
          if (eventCrfBeans.isEmpty()) {
            logger.debug("String_Node_Str" + studyEventBean.getId() + "String_Node_Str"+ studyEventBean.getLocation());
            if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) {
              EventCRFBean newEventCrfBean=new EventCRFBean();
              newEventCrfBean.setStudyEventId(studyEventBean.getId());
              newEventCrfBean.setStudySubjectId(studySubjectBean.getId());
              newEventCrfBean.setCRFVersionId(crfVersionBean.getId());
              newEventCrfBean.setDateInterviewed(new Date());
              newEventCrfBean.setOwner(ub);
              newEventCrfBean.setInterviewerName(ub.getName());
              newEventCrfBean.setCompletionStatusId(1);
              newEventCrfBean.setStatus(Status.AVAILABLE);
              newEventCrfBean.setStage(DataEntryStage.INITIAL_DATA_ENTRY);
              newEventCrfBean=(EventCRFBean)eventCrfDAO.create(newEventCrfBean);
              eventCrfBeans.add(newEventCrfBean);
              logger.debug("String_Node_Str");
            }
          }
 else {
          }
          for (          EventCRFBean ecb : eventCrfBeans) {
            Integer ecbId=new Integer(ecb.getId());
            if (!eventCRFBeanIds.contains(ecbId)) {
              eventCRFBeans.add(ecb);
              eventCRFBeanIds.add(ecbId);
            }
          }
        }
      }
    }
  }
  return eventCRFBeans;
}