Program: 115146
Project: 115146
Buggy source:
private ArrayList<DiscrepancyNoteBean> populateRowsWithAttachedData(ArrayList noteRows){
  DiscrepancyNoteDAO dndao=getDiscrepancyNoteDao();
  ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
  for (int i=0; i < noteRows.size(); i++) {
    DiscrepancyNoteBean dnb=(DiscrepancyNoteBean)noteRows.get(i);
    dnb.setAssignedUser((UserAccountBean)getUserAccountDao().findByPK(dnb.getAssignedUserId()));
    if (dnb.getParentDnId() == 0) {
      ArrayList children=dndao.findAllByStudyAndParent(currentStudy,dnb.getId());
      dnb.setNumChildren(children.size());
      for (int j=0; j < children.size(); j++) {
        DiscrepancyNoteBean child=(DiscrepancyNoteBean)children.get(j);
        dnb.setUpdatedDate(child.getCreatedDate());
      }
    }
    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")) {
        allNotes.add(dnb);
        SubjectBean sb=(SubjectBean)aeb;
        StudySubjectBean ssb=studySubjectDao.findBySubjectIdAndStudy(sb.getId(),currentStudy);
        dnb.setStudySub(ssb);
        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")) {
        allNotes.add(dnb);
        StudySubjectBean ssb=(StudySubjectBean)aeb;
        dnb.setStudySub(ssb);
        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")) {
        StudyEventDAO sed=getStudyEventDao();
        StudyEventBean se=(StudyEventBean)sed.findByPK(dnb.getEntityId());
        EventCRFBean ecb=(EventCRFBean)aeb;
        CRFVersionDAO cvdao=getCrfVersionDao();
        CRFDAO cdao=getCrfDao();
        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)getStudySubjectDao().findByPK(ecb.getStudySubjectId());
        dnb.setStudySub(ssub);
        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")) {
        allNotes.add(dnb);
        StudyEventDAO sed=getStudyEventDao();
        StudyEventBean se=(StudyEventBean)sed.findByPK(dnb.getEntityId());
        StudyEventDefinitionDAO seddao=getStudyEventDefinitionDao();
        StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
        se.setName(sedb.getName());
        dnb.setEntityName(sedb.getName());
        StudySubjectBean ssub=(StudySubjectBean)getStudySubjectDao().findByPK(se.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setEventStart(se.getDateStarted());
        dnb.setEventName(se.getName());
        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")) {
        ItemDataDAO iddao=getItemDataDao();
        ItemDAO idao=getItemDao();
        ItemDataBean idb=(ItemDataBean)iddao.findByPK(dnb.getEntityId());
        ItemBean ib=(ItemBean)idao.findByPK(idb.getItemId());
        EventCRFDAO ecdao=getEventCRFDao();
        EventCRFBean ec=(EventCRFBean)ecdao.findByPK(idb.getEventCRFId());
        CRFVersionDAO cvdao=getCrfVersionDao();
        CRFDAO cdao=getCrfDao();
        CRFVersionBean cvb=(CRFVersionBean)cvdao.findByPK(ec.getCRFVersionId());
        CRFBean cb=(CRFBean)cdao.findByPK(cvb.getCrfId());
        allNotes.add(dnb);
        dnb.setStageId(ec.getStage().getId());
        dnb.setEntityName(ib.getName());
        dnb.setEntityValue(idb.getValue());
        dnb.setItemId(ib.getId());
        StudyEventDAO sed=getStudyEventDao();
        StudyEventBean se=(StudyEventBean)sed.findByPK(ec.getStudyEventId());
        StudyEventDefinitionDAO seddao=getStudyEventDefinitionDao();
        StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
        se.setName(sedb.getName());
        StudySubjectDAO ssdao=getStudySubjectDao();
        StudySubjectBean ssub=(StudySubjectBean)ssdao.findByPK(ec.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setEventStart(se.getDateStarted());
        dnb.setEventName(se.getName());
        dnb.setCrfName(cb.getName());
      }
      dnb.setSubjectId(dnb.getStudySub().getId());
    }
    dnb.setSiteId(((StudyBean)getStudyDao().findByPK(dnb.getStudySub().getStudyId())).getIdentifier());
  }
  return allNotes;
}

Fixed version (ground truth):
private ArrayList<DiscrepancyNoteBean> populateRowsWithAttachedData(ArrayList noteRows){
  DiscrepancyNoteDAO dndao=getDiscrepancyNoteDao();
  ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
  for (int i=0; i < noteRows.size(); i++) {
    DiscrepancyNoteBean dnb=(DiscrepancyNoteBean)noteRows.get(i);
    dnb.setAssignedUser((UserAccountBean)getUserAccountDao().findByPK(dnb.getAssignedUserId()));
    if (dnb.getParentDnId() == 0) {
      ArrayList children=dndao.findAllByStudyAndParent(currentStudy,dnb.getId());
      dnb.setNumChildren(children.size());
      for (int j=0; j < children.size(); j++) {
        DiscrepancyNoteBean child=(DiscrepancyNoteBean)children.get(j);
        dnb.setUpdatedDate(child.getCreatedDate());
      }
    }
    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")) {
        allNotes.add(dnb);
        SubjectBean sb=(SubjectBean)aeb;
        StudySubjectBean ssb=studySubjectDao.findBySubjectIdAndStudy(sb.getId(),currentStudy);
        dnb.setStudySub(ssb);
        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")) {
        allNotes.add(dnb);
        StudySubjectBean ssb=(StudySubjectBean)aeb;
        dnb.setStudySub(ssb);
        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")) {
        StudyEventDAO sed=getStudyEventDao();
        StudyEventBean se=(StudyEventBean)sed.findByPK(dnb.getEntityId());
        EventCRFBean ecb=(EventCRFBean)aeb;
        CRFVersionDAO cvdao=getCrfVersionDao();
        CRFDAO cdao=getCrfDao();
        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)getStudySubjectDao().findByPK(ecb.getStudySubjectId());
        dnb.setStudySub(ssub);
        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")) {
        allNotes.add(dnb);
        StudyEventDAO sed=getStudyEventDao();
        StudyEventBean se=(StudyEventBean)sed.findByPK(dnb.getEntityId());
        StudyEventDefinitionDAO seddao=getStudyEventDefinitionDao();
        StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
        se.setName(sedb.getName());
        dnb.setEntityName(sedb.getName());
        StudySubjectBean ssub=(StudySubjectBean)getStudySubjectDao().findByPK(se.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setEventStart(se.getDateStarted());
        dnb.setEventName(se.getName());
        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")) {
        ItemDataDAO iddao=getItemDataDao();
        ItemDAO idao=getItemDao();
        ItemDataBean idb=(ItemDataBean)iddao.findByPK(dnb.getEntityId());
        ItemBean ib=(ItemBean)idao.findByPK(idb.getItemId());
        EventCRFDAO ecdao=getEventCRFDao();
        EventCRFBean ec=(EventCRFBean)ecdao.findByPK(idb.getEventCRFId());
        CRFVersionDAO cvdao=getCrfVersionDao();
        CRFDAO cdao=getCrfDao();
        CRFVersionBean cvb=(CRFVersionBean)cvdao.findByPK(ec.getCRFVersionId());
        CRFBean cb=(CRFBean)cdao.findByPK(cvb.getCrfId());
        allNotes.add(dnb);
        dnb.setStageId(ec.getStage().getId());
        dnb.setEntityName(ib.getName());
        dnb.setEntityValue(idb.getValue());
        dnb.setItemId(ib.getId());
        StudyEventDAO sed=getStudyEventDao();
        StudyEventBean se=(StudyEventBean)sed.findByPK(ec.getStudyEventId());
        StudyEventDefinitionDAO seddao=getStudyEventDefinitionDao();
        StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
        se.setName(sedb.getName());
        StudySubjectDAO ssdao=getStudySubjectDao();
        StudySubjectBean ssub=(StudySubjectBean)ssdao.findByPK(ec.getStudySubjectId());
        dnb.setStudySub(ssub);
        dnb.setEventStart(se.getDateStarted());
        dnb.setEventName(se.getName());
        dnb.setCrfName(cb.getName());
        dnb.setCrfStatus(ec.getStatus().getName());
      }
      dnb.setSubjectId(dnb.getStudySub().getId());
    }
    dnb.setSiteId(((StudyBean)getStudyDao().findByPK(dnb.getStudySub().getStudyId())).getIdentifier());
  }
  return allNotes;
}