Program: 115145
Project: 115145
Buggy source:
private ArrayList<DiscrepancyNoteBean> populateRowsWithAttachedData(ArrayList<DiscrepancyNoteBean> noteRows){
  Locale l=request.getLocale();
  resword=ResourceBundleProvider.getWordsBundle(l);
  resformat=ResourceBundleProvider.getFormatBundle(l);
  SimpleDateFormat sdf=new SimpleDateFormat(resformat.getString("String_Node_Str"),ResourceBundleProvider.getLocale());
  DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  StudySubjectDAO studySubjectDAO=new StudySubjectDAO(sm.getDataSource());
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  CRFVersionDAO cvdao=new CRFVersionDAO(sm.getDataSource());
  CRFDAO cdao=new CRFDAO(sm.getDataSource());
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
  ItemDataDAO iddao=new ItemDataDAO(sm.getDataSource());
  ItemDAO idao=new ItemDAO(sm.getDataSource());
  StudyDAO studyDao=new StudyDAO(sm.getDataSource());
  ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
  for (int i=0; i < noteRows.size(); i++) {
    DiscrepancyNoteBean dnb=noteRows.get(i);
    dnb.setCreatedDateString(dnb.getCreatedDate() == null ? "String_Node_Str" : sdf.format(dnb.getCreatedDate()));
    if (dnb.getParentDnId() == 0) {
      ArrayList children=dndao.findAllByStudyAndParent(currentStudy,dnb.getId());
      children=children == null ? new ArrayList() : children;
      dnb.setNumChildren(children.size());
      dnb.setChildren(children);
      int lastDnId=dnb.getId();
      int lastChild=0;
      for (int j=0; j < children.size(); j++) {
        DiscrepancyNoteBean child=(DiscrepancyNoteBean)children.get(j);
        child.setCreatedDateString(child.getCreatedDate() == null ? "String_Node_Str" : sdf.format(child.getCreatedDate()));
        child.setUpdatedDateString(child.getCreatedDate() != null ? sdf.format(child.getCreatedDate()) : "String_Node_Str");
        if (child.getId() > lastDnId) {
          lastDnId=child.getId();
          lastChild=j;
        }
      }
      if (children.size() > 0) {
        DiscrepancyNoteBean lastdn=(DiscrepancyNoteBean)children.get(lastChild);
        dnb.setUpdatedDate(lastdn.getCreatedDate());
        dnb.setUpdatedDateString(dnb.getUpdatedDate() != null ? sdf.format(dnb.getUpdatedDate()) : "String_Node_Str");
      }
    }
    String entityType=dnb.getEntityType();
    if (dnb.getEntityId() > 0 && !entityType.equals("String_Node_Str")) {
      AuditableEntityBean aeb=dndao.findEntity(dnb);
      dnb.setEntityName(aeb.getName());
      if (entityType.equalsIgnoreCase("String_Node_Str")) {
        SubjectBean sb=(SubjectBean)aeb;
        StudySubjectBean ssb=studySubjectDAO.findBySubjectIdAndStudy(sb.getId(),currentStudy);
        dnb.setStudySub(ssb);
        dnb.setSubjectName(ssb.getLabel());
        String column=dnb.getColumn().trim();
        if (!StringUtil.isBlank(column)) {
          if ("String_Node_Str".equalsIgnoreCase(column)) {
            dnb.setEntityValue(sb.getGender() + "String_Node_Str");
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equals(column)) {
            if (sb.getDateOfBirth() != null) {
              dnb.setEntityValue(sb.getDateOfBirth().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equalsIgnoreCase(column)) {
            dnb.setEntityName(resword.getString("String_Node_Str"));
            dnb.setEntityValue(sb.getUniqueIdentifier());
          }
        }
      }
 else       if (entityType.equalsIgnoreCase("String_Node_Str")) {
        StudySubjectBean ssb=(StudySubjectBean)aeb;
        dnb.setStudySub(ssb);
        dnb.setSubjectName(ssb.getLabel());
        String column=dnb.getColumn().trim();
        if (!StringUtil.isBlank(column)) {
          if ("String_Node_Str".equals(column)) {
            if (ssb.getEnrollmentDate() != null) {
              dnb.setEntityValue(ssb.getEnrollmentDate().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
        }
      }
 else       if (entityType.equalsIgnoreCase("String_Node_Str")) {
        StudyEventBean se=(StudyEventBean)sedao.findByPK(dnb.getEntityId());
        EventCRFBean ecb=(EventCRFBean)aeb;
        CRFVersionBean cvb=(CRFVersionBean)cvdao.findByPK(ecb.getCRFVersionId());
        CRFBean cb=(CRFBean)cdao.findByPK(cvb.getCrfId());
        dnb.setStageId(ecb.getStage().getId());
        dnb.setEntityName(cb.getName() + "String_Node_Str" + cvb.getName()+ "String_Node_Str");
        StudySubjectBean ssub=(StudySubjectBean)studySubjectDAO.findByPK(ecb.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setSubjectName(ssub.getLabel());
        if (se != null) {
          dnb.setEventStart(se.getDateStarted());
          dnb.setEventName(se.getName());
        }
        dnb.setCrfName(cb.getName());
        String column=dnb.getColumn().trim();
        if (!StringUtil.isBlank(column)) {
          if ("String_Node_Str".equals(column)) {
            if (ecb.getDateInterviewed() != null) {
              dnb.setEntityValue(ecb.getDateInterviewed().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equals(column)) {
            dnb.setEntityValue(ecb.getInterviewerName());
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
        }
      }
 else       if (entityType.equalsIgnoreCase("String_Node_Str")) {
        StudyEventBean se=(StudyEventBean)sedao.findByPK(dnb.getEntityId());
        StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
        se.setName(sedb.getName());
        dnb.setEntityName(sedb.getName());
        StudySubjectBean ssub=(StudySubjectBean)studySubjectDAO.findByPK(se.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setEventStart(se.getDateStarted());
        dnb.setEventName(se.getName());
        dnb.setSubjectName(ssub.getLabel());
        String column=dnb.getColumn().trim();
        if (!StringUtil.isBlank(column)) {
          if ("String_Node_Str".equals(column)) {
            if (se.getDateStarted() != null) {
              dnb.setEntityValue(se.getDateStarted().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equals(column)) {
            if (se.getDateEnded() != null) {
              dnb.setEntityValue(se.getDateEnded().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equals(column)) {
            dnb.setEntityValue(se.getLocation());
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
        }
      }
 else       if (entityType.equalsIgnoreCase("String_Node_Str")) {
        ItemDataBean idb=(ItemDataBean)iddao.findByPK(dnb.getEntityId());
        ItemBean ib=(ItemBean)idao.findByPK(idb.getItemId());
        EventCRFBean ec=(EventCRFBean)ecdao.findByPK(idb.getEventCRFId());
        CRFVersionBean cvb=(CRFVersionBean)cvdao.findByPK(ec.getCRFVersionId());
        CRFBean cb=(CRFBean)cdao.findByPK(cvb.getCrfId());
        dnb.setStageId(ec.getStage().getId());
        dnb.setEntityName(ib.getName());
        dnb.setEntityValue(idb.getValue());
        StudyEventBean se=(StudyEventBean)sedao.findByPK(ec.getStudyEventId());
        StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
        se.setName(sedb.getName());
        StudySubjectBean ssub=(StudySubjectBean)studySubjectDAO.findByPK(ec.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setSubjectName(ssub.getLabel());
        dnb.setEventStart(se.getDateStarted());
        dnb.setEventName(se.getName());
        dnb.setCrfName(cb.getName());
      }
    }
    dnb.setStudy((StudyBean)studyDao.findByPK(dnb.getStudyId()));
    if (dnb.getParentDnId() == 0 && dnb.getChildren().size() > 0) {
      ArrayList<DiscrepancyNoteBean> children=dnb.getChildren();
      int childrenSize=children.size();
      for (int j=0; j < childrenSize; j++) {
        DiscrepancyNoteBean child=children.get(j);
        child.setSubjectName(dnb.getSubjectName());
        child.setEventName(dnb.getEventName());
        child.setCrfName(dnb.getCrfName());
        child.setEntityName(dnb.getEntityName());
        child.setEntityValue(dnb.getEntityValue());
        child.setStudySub(dnb.getStudySub());
        child.setStudy(dnb.getStudy());
      }
    }
    allNotes.add(dnb);
  }
  return allNotes;
}

Fixed version (ground truth):
private ArrayList<DiscrepancyNoteBean> populateRowsWithAttachedData(ArrayList<DiscrepancyNoteBean> noteRows){
  Locale l=request.getLocale();
  resword=ResourceBundleProvider.getWordsBundle(l);
  resformat=ResourceBundleProvider.getFormatBundle(l);
  SimpleDateFormat sdf=new SimpleDateFormat(resformat.getString("String_Node_Str"),ResourceBundleProvider.getLocale());
  DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  StudySubjectDAO studySubjectDAO=new StudySubjectDAO(sm.getDataSource());
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  CRFVersionDAO cvdao=new CRFVersionDAO(sm.getDataSource());
  CRFDAO cdao=new CRFDAO(sm.getDataSource());
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
  ItemDataDAO iddao=new ItemDataDAO(sm.getDataSource());
  ItemDAO idao=new ItemDAO(sm.getDataSource());
  StudyDAO studyDao=new StudyDAO(sm.getDataSource());
  ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
  for (int i=0; i < noteRows.size(); i++) {
    DiscrepancyNoteBean dnb=noteRows.get(i);
    dnb.setCreatedDateString(dnb.getCreatedDate() == null ? "String_Node_Str" : sdf.format(dnb.getCreatedDate()));
    if (dnb.getParentDnId() == 0) {
      ArrayList children=dndao.findAllByStudyAndParent(currentStudy,dnb.getId());
      children=children == null ? new ArrayList() : children;
      dnb.setNumChildren(children.size());
      dnb.setChildren(children);
      int lastDnId=dnb.getId();
      int lastChild=0;
      for (int j=0; j < children.size(); j++) {
        DiscrepancyNoteBean child=(DiscrepancyNoteBean)children.get(j);
        child.setCreatedDateString(child.getCreatedDate() == null ? "String_Node_Str" : sdf.format(child.getCreatedDate()));
        child.setUpdatedDateString(child.getCreatedDate() != null ? sdf.format(child.getCreatedDate()) : "String_Node_Str");
        if (child.getId() > lastDnId) {
          lastDnId=child.getId();
          lastChild=j;
        }
      }
      if (children.size() > 0) {
        DiscrepancyNoteBean lastdn=(DiscrepancyNoteBean)children.get(lastChild);
        dnb.setUpdatedDate(lastdn.getCreatedDate());
        dnb.setUpdatedDateString(dnb.getUpdatedDate() != null ? sdf.format(dnb.getUpdatedDate()) : "String_Node_Str");
      }
    }
    String entityType=dnb.getEntityType();
    if (dnb.getEntityId() > 0 && !entityType.equals("String_Node_Str")) {
      AuditableEntityBean aeb=dndao.findEntity(dnb);
      dnb.setEntityName(aeb.getName());
      if (entityType.equalsIgnoreCase("String_Node_Str")) {
        SubjectBean sb=(SubjectBean)aeb;
        StudySubjectBean ssb=studySubjectDAO.findBySubjectIdAndStudy(sb.getId(),currentStudy);
        dnb.setStudySub(ssb);
        dnb.setSubjectName(ssb.getLabel());
        String column=dnb.getColumn().trim();
        if (!StringUtil.isBlank(column)) {
          if ("String_Node_Str".equalsIgnoreCase(column)) {
            dnb.setEntityValue(sb.getGender() + "String_Node_Str");
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equals(column)) {
            if (sb.getDateOfBirth() != null) {
              dnb.setEntityValue(sb.getDateOfBirth().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equalsIgnoreCase(column)) {
            dnb.setEntityName(resword.getString("String_Node_Str"));
            dnb.setEntityValue(sb.getUniqueIdentifier());
          }
        }
      }
 else       if (entityType.equalsIgnoreCase("String_Node_Str")) {
        StudySubjectBean ssb=(StudySubjectBean)aeb;
        dnb.setStudySub(ssb);
        dnb.setSubjectName(ssb.getLabel());
        String column=dnb.getColumn().trim();
        if (!StringUtil.isBlank(column)) {
          if ("String_Node_Str".equals(column)) {
            if (ssb.getEnrollmentDate() != null) {
              dnb.setEntityValue(ssb.getEnrollmentDate().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
        }
      }
 else       if (entityType.equalsIgnoreCase("String_Node_Str")) {
        StudyEventBean se=(StudyEventBean)sedao.findByPK(dnb.getEntityId());
        EventCRFBean ecb=(EventCRFBean)aeb;
        CRFVersionBean cvb=(CRFVersionBean)cvdao.findByPK(ecb.getCRFVersionId());
        CRFBean cb=(CRFBean)cdao.findByPK(cvb.getCrfId());
        dnb.setStageId(ecb.getStage().getId());
        dnb.setEntityName(cb.getName() + "String_Node_Str" + cvb.getName()+ "String_Node_Str");
        StudySubjectBean ssub=(StudySubjectBean)studySubjectDAO.findByPK(ecb.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setSubjectName(ssub.getLabel());
        if (se != null) {
          dnb.setEventStart(se.getDateStarted());
          dnb.setEventName(se.getName());
        }
        dnb.setCrfName(cb.getName());
        dnb.setCrfStatus(ecb.getStatus().getName());
        String column=dnb.getColumn().trim();
        if (!StringUtil.isBlank(column)) {
          if ("String_Node_Str".equals(column)) {
            if (ecb.getDateInterviewed() != null) {
              dnb.setEntityValue(ecb.getDateInterviewed().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equals(column)) {
            dnb.setEntityValue(ecb.getInterviewerName());
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
        }
      }
 else       if (entityType.equalsIgnoreCase("String_Node_Str")) {
        StudyEventBean se=(StudyEventBean)sedao.findByPK(dnb.getEntityId());
        StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
        se.setName(sedb.getName());
        dnb.setEntityName(sedb.getName());
        StudySubjectBean ssub=(StudySubjectBean)studySubjectDAO.findByPK(se.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setEventStart(se.getDateStarted());
        dnb.setEventName(se.getName());
        dnb.setSubjectName(ssub.getLabel());
        String column=dnb.getColumn().trim();
        if (!StringUtil.isBlank(column)) {
          if ("String_Node_Str".equals(column)) {
            if (se.getDateStarted() != null) {
              dnb.setEntityValue(se.getDateStarted().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equals(column)) {
            if (se.getDateEnded() != null) {
              dnb.setEntityValue(se.getDateEnded().toString());
            }
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
 else           if ("String_Node_Str".equals(column)) {
            dnb.setEntityValue(se.getLocation());
            dnb.setEntityName(resword.getString("String_Node_Str"));
          }
        }
      }
 else       if (entityType.equalsIgnoreCase("String_Node_Str")) {
        ItemDataBean idb=(ItemDataBean)iddao.findByPK(dnb.getEntityId());
        ItemBean ib=(ItemBean)idao.findByPK(idb.getItemId());
        EventCRFBean ec=(EventCRFBean)ecdao.findByPK(idb.getEventCRFId());
        CRFVersionBean cvb=(CRFVersionBean)cvdao.findByPK(ec.getCRFVersionId());
        CRFBean cb=(CRFBean)cdao.findByPK(cvb.getCrfId());
        dnb.setStageId(ec.getStage().getId());
        dnb.setEntityName(ib.getName());
        dnb.setEntityValue(idb.getValue());
        StudyEventBean se=(StudyEventBean)sedao.findByPK(ec.getStudyEventId());
        StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
        se.setName(sedb.getName());
        StudySubjectBean ssub=(StudySubjectBean)studySubjectDAO.findByPK(ec.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setSubjectName(ssub.getLabel());
        dnb.setEventStart(se.getDateStarted());
        dnb.setEventName(se.getName());
        dnb.setCrfName(cb.getName());
        dnb.setCrfStatus(ec.getStatus().getName());
      }
    }
    dnb.setStudy((StudyBean)studyDao.findByPK(dnb.getStudyId()));
    if (dnb.getParentDnId() == 0 && dnb.getChildren().size() > 0) {
      ArrayList<DiscrepancyNoteBean> children=dnb.getChildren();
      int childrenSize=children.size();
      for (int j=0; j < childrenSize; j++) {
        DiscrepancyNoteBean child=children.get(j);
        child.setSubjectName(dnb.getSubjectName());
        child.setEventName(dnb.getEventName());
        child.setCrfName(dnb.getCrfName());
        child.setCrfStatus(dnb.getCrfStatus());
        child.setEntityName(dnb.getEntityName());
        child.setEntityValue(dnb.getEntityValue());
        child.setStudySub(dnb.getStudySub());
        child.setStudy(dnb.getStudy());
      }
    }
    allNotes.add(dnb);
  }
  return allNotes;
}