Program: 115166
Project: 115166
Buggy source:
@Override public void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  FormProcessor fp=new FormProcessor(request);
  int siteId=fp.getInt("String_Node_Str");
  EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
  SectionBean sb=(SectionBean)request.getAttribute(SECTION_BEAN);
  StudyEventDefinitionDAO sedao=new StudyEventDefinitionDAO(getDataSource());
  EventDefinitionCRFDAO edao=new EventDefinitionCRFDAO(getDataSource());
  EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(getDataSource());
  ArrayList<SectionBean> allSectionBeans;
  StudyDAO studyDao=new StudyDAO(getDataSource());
  StudyBean site=(StudyBean)studyDao.findByPK(siteId);
  ArrayList<StudyEventDefinitionBean> seds=new ArrayList<StudyEventDefinitionBean>();
  seds=sedao.findAllByStudy(site);
  CRFVersionDAO cvdao=new CRFVersionDAO(getDataSource());
  CRFDAO cdao=new CRFDAO(getDataSource());
  boolean isSubmitted=false;
  ArrayList<EventDefinitionCRFBean> edcs=new ArrayList();
  for (  StudyEventDefinitionBean sed : seds) {
    int defId=sed.getId();
    edcs.addAll(edcdao.findAllByDefinitionAndSiteIdAndParentStudyId(defId,siteId,site.getParentStudyId()));
  }
  Map eventDefinitionDefaultVersions=new LinkedHashMap();
  for (int i=0; i < edcs.size(); i++) {
    EventDefinitionCRFBean edc=edcs.get(i);
    if (!edc.getStatus().equals(Status.AVAILABLE)) {
      continue;
    }
    ArrayList versions=(ArrayList)cvdao.findAllByCRF(edc.getCrfId());
    edc.setVersions(versions);
    CRFBean crf=(CRFBean)cdao.findByPK(edc.getCrfId());
    edc.setCrfName(crf.getName());
    if (crf.getStatus().equals(Status.AVAILABLE)) {
      edc.setOwner(crf.getOwner());
    }
    CRFVersionBean defaultVersion=(CRFVersionBean)cvdao.findByPK(edc.getDefaultVersionId());
    StudyEventDefinitionBean studyEventDefinitionBean=(StudyEventDefinitionBean)sedao.findByPK(edc.getStudyEventDefinitionId());
    edc.setDefaultVersionName(defaultVersion.getName());
    if (defaultVersion.getStatus().isAvailable()) {
      List list=(ArrayList)eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
      if (list == null)       list=new ArrayList();
      list.add(defaultVersion);
      eventDefinitionDefaultVersions.put(studyEventDefinitionBean,list);
    }
  }
  String isIE=fp.getString("String_Node_Str");
  if ("String_Node_Str".equalsIgnoreCase(isIE)) {
    request.setAttribute("String_Node_Str","String_Node_Str");
  }
  SectionDAO sdao=new SectionDAO(getDataSource());
  CRFVersionDAO crfVersionDAO=new CRFVersionDAO(getDataSource());
  CRFDAO crfDao=new CRFDAO(getDataSource());
  Map sedCrfBeans=null;
  for (Iterator it=eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
    if (sedCrfBeans == null)     sedCrfBeans=new LinkedHashMap();
    StudyEventDefinitionBean sedBean=(StudyEventDefinitionBean)it.next();
    List crfVersions=(ArrayList)eventDefinitionDefaultVersions.get(sedBean);
    for (Iterator crfIt=crfVersions.iterator(); crfIt.hasNext(); ) {
      CRFVersionBean crfVersionBean=(CRFVersionBean)crfIt.next();
      allSectionBeans=new ArrayList<SectionBean>();
      ArrayList sectionBeans=new ArrayList();
      ItemGroupDAO itemGroupDao=new ItemGroupDAO(getDataSource());
      List<ItemGroupBean> itemGroupBeans=itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
      CRFBean crfBean=crfDao.findByVersionId(crfVersionBean.getId());
      if (itemGroupBeans.size() > 0) {
        DisplaySectionBeanHandler handler=new DisplaySectionBeanHandler(false,getDataSource(),getServletContext());
        handler.setCrfVersionId(crfVersionBean.getId());
        List<DisplaySectionBean> displaySectionBeans=handler.getDisplaySectionBeans();
        request.setAttribute("String_Node_Str",displaySectionBeans);
        CRFVersionBean crfverBean=(CRFVersionBean)crfVersionDAO.findByPK(crfVersionBean.getId());
        request.setAttribute("String_Node_Str",crfverBean);
        request.setAttribute("String_Node_Str",crfBean);
        request.setAttribute("String_Node_Str","String_Node_Str");
        PrintCRFBean printCrfBean=new PrintCRFBean();
        printCrfBean.setDisplaySectionBeans(displaySectionBeans);
        printCrfBean.setCrfVersionBean(crfVersionBean);
        printCrfBean.setCrfBean(crfBean);
        printCrfBean.setEventCrfBean(ecb);
        printCrfBean.setGrouped(true);
        List list=(ArrayList)sedCrfBeans.get(sedBean);
        if (list == null)         list=new ArrayList();
        list.add(printCrfBean);
        sedCrfBeans.put(sedBean,list);
        continue;
      }
      ecb=new EventCRFBean();
      ecb.setCRFVersionId(crfVersionBean.getId());
      CRFVersionBean version=(CRFVersionBean)crfVersionDAO.findByPK(crfVersionBean.getId());
      ArrayList sects=(ArrayList)sdao.findByVersionId(version.getId());
      for (int i=0; i < sects.size(); i++) {
        sb=(SectionBean)sects.get(i);
        int sectId=sb.getId();
        if (sectId > 0) {
          allSectionBeans.add((SectionBean)sdao.findByPK(sectId));
        }
      }
      request.setAttribute(INPUT_EVENT_CRF,ecb);
      request.setAttribute(SECTION_BEAN,sb);
      request.setAttribute(ALL_SECTION_BEANS,allSectionBeans);
      sectionBeans=super.getAllDisplayBeans(request);
      DisplaySectionBean dsb=super.getDisplayBean(false,false,request,isSubmitted);
      PrintCRFBean printCrfBean=new PrintCRFBean();
      printCrfBean.setAllSections(sectionBeans);
      printCrfBean.setDisplaySectionBean(dsb);
      printCrfBean.setEventCrfBean(ecb);
      printCrfBean.setCrfVersionBean(crfVersionBean);
      printCrfBean.setCrfBean(crfBean);
      printCrfBean.setGrouped(false);
      List list=(ArrayList)sedCrfBeans.get(sedBean);
      if (list == null)       list=new ArrayList();
      list.add(printCrfBean);
      sedCrfBeans.put(sedBean,list);
    }
  }
  StudyBean parentStudy=(StudyBean)studyDao.findByPK(site.getParentStudyId());
  String studyName=parentStudy.getName();
  String siteName=site.getName();
  request.setAttribute("String_Node_Str",sedCrfBeans);
  request.setAttribute("String_Node_Str",studyName);
  request.setAttribute("String_Node_Str",siteName);
  forwardPage(Page.VIEW_ALL_SITE_DEFAULT_CRF_VERSIONS_PRINT,request,response);
}

Fixed version (ground truth):
@Override public void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  FormProcessor fp=new FormProcessor(request);
  int siteId=fp.getInt("String_Node_Str");
  EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
  SectionBean sb=(SectionBean)request.getAttribute(SECTION_BEAN);
  StudyEventDefinitionDAO sedao=new StudyEventDefinitionDAO(getDataSource());
  EventDefinitionCRFDAO edao=new EventDefinitionCRFDAO(getDataSource());
  EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(getDataSource());
  ArrayList<SectionBean> allSectionBeans;
  StudyDAO studyDao=new StudyDAO(getDataSource());
  StudyBean site=(StudyBean)studyDao.findByPK(siteId);
  ArrayList<StudyEventDefinitionBean> seds=new ArrayList<StudyEventDefinitionBean>();
  seds=sedao.findAllByStudy(site);
  CRFVersionDAO cvdao=new CRFVersionDAO(getDataSource());
  CRFDAO cdao=new CRFDAO(getDataSource());
  boolean isSubmitted=false;
  ArrayList<EventDefinitionCRFBean> edcs=new ArrayList();
  for (  StudyEventDefinitionBean sed : seds) {
    int defId=sed.getId();
    edcs.addAll(edcdao.findAllByDefinitionAndSiteIdAndParentStudyId(defId,siteId,site.getParentStudyId()));
  }
  Map eventDefinitionDefaultVersions=new LinkedHashMap();
  Map eventDefinitionEventDefCrf=new LinkedHashMap<StudyEventDefinitionBean,EventDefinitionCRFBean>();
  for (int i=0; i < edcs.size(); i++) {
    EventDefinitionCRFBean edc=edcs.get(i);
    if (!edc.getStatus().equals(Status.AVAILABLE)) {
      continue;
    }
    ArrayList versions=(ArrayList)cvdao.findAllByCRF(edc.getCrfId());
    edc.setVersions(versions);
    CRFBean crf=(CRFBean)cdao.findByPK(edc.getCrfId());
    edc.setCrfName(crf.getName());
    if (crf.getStatus().equals(Status.AVAILABLE)) {
      edc.setOwner(crf.getOwner());
    }
    CRFVersionBean defaultVersion=(CRFVersionBean)cvdao.findByPK(edc.getDefaultVersionId());
    StudyEventDefinitionBean studyEventDefinitionBean=(StudyEventDefinitionBean)sedao.findByPK(edc.getStudyEventDefinitionId());
    edc.setDefaultVersionName(defaultVersion.getName());
    if (defaultVersion.getStatus().isAvailable()) {
      List list=(ArrayList)eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
      if (list == null)       list=new ArrayList();
      list.add(defaultVersion);
      eventDefinitionDefaultVersions.put(studyEventDefinitionBean,list);
      eventDefinitionEventDefCrf.put(studyEventDefinitionBean,edc);
    }
  }
  String isIE=fp.getString("String_Node_Str");
  if ("String_Node_Str".equalsIgnoreCase(isIE)) {
    request.setAttribute("String_Node_Str","String_Node_Str");
  }
  SectionDAO sdao=new SectionDAO(getDataSource());
  CRFVersionDAO crfVersionDAO=new CRFVersionDAO(getDataSource());
  CRFDAO crfDao=new CRFDAO(getDataSource());
  Map sedCrfBeans=null;
  for (Iterator it=eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
    if (sedCrfBeans == null)     sedCrfBeans=new LinkedHashMap();
    StudyEventDefinitionBean sedBean=(StudyEventDefinitionBean)it.next();
    List crfVersions=(ArrayList)eventDefinitionDefaultVersions.get(sedBean);
    for (Iterator crfIt=crfVersions.iterator(); crfIt.hasNext(); ) {
      CRFVersionBean crfVersionBean=(CRFVersionBean)crfIt.next();
      allSectionBeans=new ArrayList<SectionBean>();
      ArrayList sectionBeans=new ArrayList();
      ItemGroupDAO itemGroupDao=new ItemGroupDAO(getDataSource());
      List<ItemGroupBean> itemGroupBeans=itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
      CRFBean crfBean=crfDao.findByVersionId(crfVersionBean.getId());
      if (itemGroupBeans.size() > 0) {
        DisplaySectionBeanHandler handler=new DisplaySectionBeanHandler(false,getDataSource(),getServletContext());
        handler.setCrfVersionId(crfVersionBean.getId());
        List<DisplaySectionBean> displaySectionBeans=handler.getDisplaySectionBeans();
        request.setAttribute("String_Node_Str",displaySectionBeans);
        CRFVersionBean crfverBean=(CRFVersionBean)crfVersionDAO.findByPK(crfVersionBean.getId());
        request.setAttribute("String_Node_Str",crfverBean);
        request.setAttribute("String_Node_Str",crfBean);
        request.setAttribute("String_Node_Str","String_Node_Str");
        PrintCRFBean printCrfBean=new PrintCRFBean();
        printCrfBean.setDisplaySectionBeans(displaySectionBeans);
        printCrfBean.setCrfVersionBean(crfVersionBean);
        printCrfBean.setCrfBean(crfBean);
        printCrfBean.setEventCrfBean(ecb);
        printCrfBean.setGrouped(true);
        List list=(ArrayList)sedCrfBeans.get(sedBean);
        if (list == null)         list=new ArrayList();
        list.add(printCrfBean);
        sedCrfBeans.put(sedBean,list);
        continue;
      }
      ecb=new EventCRFBean();
      ecb.setCRFVersionId(crfVersionBean.getId());
      CRFVersionBean version=(CRFVersionBean)crfVersionDAO.findByPK(crfVersionBean.getId());
      ArrayList sects=(ArrayList)sdao.findByVersionId(version.getId());
      for (int i=0; i < sects.size(); i++) {
        sb=(SectionBean)sects.get(i);
        int sectId=sb.getId();
        if (sectId > 0) {
          allSectionBeans.add((SectionBean)sdao.findByPK(sectId));
        }
      }
      EventDefinitionCRFBean edcBean=(EventDefinitionCRFBean)eventDefinitionEventDefCrf.get(sedBean);
      request.setAttribute(EVENT_DEF_CRF_BEAN,edcBean);
      request.setAttribute(INPUT_EVENT_CRF,ecb);
      request.setAttribute(SECTION_BEAN,sb);
      request.setAttribute(ALL_SECTION_BEANS,allSectionBeans);
      sectionBeans=super.getAllDisplayBeans(request);
      DisplaySectionBean dsb=super.getDisplayBean(false,false,request,isSubmitted);
      PrintCRFBean printCrfBean=new PrintCRFBean();
      printCrfBean.setAllSections(sectionBeans);
      printCrfBean.setDisplaySectionBean(dsb);
      printCrfBean.setEventCrfBean(ecb);
      printCrfBean.setCrfVersionBean(crfVersionBean);
      printCrfBean.setCrfBean(crfBean);
      printCrfBean.setGrouped(false);
      List list=(ArrayList)sedCrfBeans.get(sedBean);
      if (list == null)       list=new ArrayList();
      list.add(printCrfBean);
      sedCrfBeans.put(sedBean,list);
    }
  }
  StudyBean parentStudy=(StudyBean)studyDao.findByPK(site.getParentStudyId());
  String studyName=parentStudy.getName();
  String siteName=site.getName();
  request.setAttribute("String_Node_Str",sedCrfBeans);
  request.setAttribute("String_Node_Str",studyName);
  request.setAttribute("String_Node_Str",siteName);
  forwardPage(Page.VIEW_ALL_SITE_DEFAULT_CRF_VERSIONS_PRINT,request,response);
}