Program: 115161
Project: 115161
Buggy source:
@Override public void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  FormProcessor fp=new FormProcessor(request);
  StudyBean currentStudy=(StudyBean)request.getSession().getAttribute("String_Node_Str");
  SectionBean sb=(SectionBean)request.getAttribute(SECTION_BEAN);
  int eventCRFId=fp.getInt("String_Node_Str");
  EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
  StudyEventDefinitionDAO sedao=new StudyEventDefinitionDAO(getDataSource());
  int defId=fp.getInt("String_Node_Str",true);
  boolean isSubmitted=false;
  ArrayList<SectionBean> allSectionBeans;
  if (defId == 0) {
    addPageMessage(respage.getString("String_Node_Str"),request);
    forwardPage(Page.LIST_DEFINITION_SERVLET,request,response);
  }
 else {
    StudyEventDefinitionBean sed=(StudyEventDefinitionBean)sedao.findByPK(defId);
    EventDefinitionCRFDAO edao=new EventDefinitionCRFDAO(getDataSource());
    ArrayList eventDefinitionCRFs=(ArrayList)edao.findAllByDefinition(defId);
    CRFVersionDAO cvdao=new CRFVersionDAO(getDataSource());
    CRFDAO cdao=new CRFDAO(getDataSource());
    ArrayList defaultVersions=new ArrayList();
    for (int i=0; i < eventDefinitionCRFs.size(); i++) {
      EventDefinitionCRFBean edc=(EventDefinitionCRFBean)eventDefinitionCRFs.get(i);
      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());
      if (defaultVersions.contains(defaultVersion)) {
        continue;
      }
      edc.setDefaultVersionName(defaultVersion.getName());
      if (edc.getStatus().isAvailable()) {
        defaultVersions.add(defaultVersion);
      }
    }
    String isIE=fp.getString("String_Node_Str");
    if ("String_Node_Str".equalsIgnoreCase(isIE)) {
      request.setAttribute("String_Node_Str","String_Node_Str");
    }
    int eventDefinitionCRFId=fp.getInt("String_Node_Str");
    SectionDAO sdao=new SectionDAO(getDataSource());
    CRFVersionDAO crfVersionDAO=new CRFVersionDAO(getDataSource());
    CRFDAO crfDao=new CRFDAO(getDataSource());
    ArrayList printCrfBeans=new ArrayList();
    for (Iterator it=defaultVersions.iterator(); it.hasNext(); ) {
      allSectionBeans=new ArrayList<SectionBean>();
      ArrayList sectionBeans=new ArrayList();
      CRFVersionBean crfVersionBean=(CRFVersionBean)it.next();
      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());
        handler.setEventCRFId(eventCRFId);
        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);
        printCrfBeans.add(printCrfBean);
        printCrfBean.setGrouped(true);
        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(ALL_SECTION_BEANS,allSectionBeans);
      sectionBeans=super.getAllDisplayBeans(request);
      request.setAttribute(INPUT_EVENT_CRF,ecb);
      request.setAttribute(SECTION_BEAN,sb);
      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);
      printCrfBeans.add(printCrfBean);
      printCrfBean.setGrouped(false);
    }
    String studyName=null;
    String siteName=null;
    if (currentStudy.getParentStudyId() > 0) {
      studyName=currentStudy.getParentStudyName();
      siteName=currentStudy.getName();
    }
 else {
      studyName=currentStudy.getName();
    }
    request.setAttribute("String_Node_Str",printCrfBeans);
    request.setAttribute("String_Node_Str",studyName);
    request.setAttribute("String_Node_Str",siteName);
    request.setAttribute("String_Node_Str",sed.getName());
    forwardPage(Page.VIEW_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);
  StudyBean currentStudy=(StudyBean)request.getSession().getAttribute("String_Node_Str");
  SectionBean sb=(SectionBean)request.getAttribute(SECTION_BEAN);
  int eventCRFId=fp.getInt("String_Node_Str");
  EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
  StudyEventDefinitionDAO sedao=new StudyEventDefinitionDAO(getDataSource());
  int defId=fp.getInt("String_Node_Str",true);
  boolean isSubmitted=false;
  ArrayList<SectionBean> allSectionBeans;
  if (defId == 0) {
    addPageMessage(respage.getString("String_Node_Str"),request);
    forwardPage(Page.LIST_DEFINITION_SERVLET,request,response);
  }
 else {
    StudyEventDefinitionBean sed=(StudyEventDefinitionBean)sedao.findByPK(defId);
    EventDefinitionCRFDAO edao=new EventDefinitionCRFDAO(getDataSource());
    ArrayList eventDefinitionCRFs=(ArrayList)edao.findAllByDefinition(defId);
    CRFVersionDAO cvdao=new CRFVersionDAO(getDataSource());
    CRFDAO cdao=new CRFDAO(getDataSource());
    ArrayList defaultVersions=new ArrayList();
    for (int i=0; i < eventDefinitionCRFs.size(); i++) {
      EventDefinitionCRFBean edc=(EventDefinitionCRFBean)eventDefinitionCRFs.get(i);
      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());
      if (defaultVersions.contains(defaultVersion)) {
        continue;
      }
      edc.setDefaultVersionName(defaultVersion.getName());
      if (edc.getStatus().isAvailable()) {
        defaultVersions.add(defaultVersion);
      }
    }
    String isIE=fp.getString("String_Node_Str");
    if ("String_Node_Str".equalsIgnoreCase(isIE)) {
      request.setAttribute("String_Node_Str","String_Node_Str");
    }
    int eventDefinitionCRFId=fp.getInt("String_Node_Str");
    SectionDAO sdao=new SectionDAO(getDataSource());
    CRFVersionDAO crfVersionDAO=new CRFVersionDAO(getDataSource());
    CRFDAO crfDao=new CRFDAO(getDataSource());
    ArrayList printCrfBeans=new ArrayList();
    for (Iterator it=defaultVersions.iterator(); it.hasNext(); ) {
      allSectionBeans=new ArrayList<SectionBean>();
      ArrayList sectionBeans=new ArrayList();
      CRFVersionBean crfVersionBean=(CRFVersionBean)it.next();
      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());
        handler.setEventCRFId(eventCRFId);
        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);
        printCrfBeans.add(printCrfBean);
        printCrfBean.setGrouped(true);
        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(ALL_SECTION_BEANS,allSectionBeans);
      request.setAttribute(INPUT_EVENT_CRF,ecb);
      sectionBeans=super.getAllDisplayBeans(request);
      request.setAttribute(SECTION_BEAN,sb);
      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);
      printCrfBeans.add(printCrfBean);
      printCrfBean.setGrouped(false);
    }
    String studyName=null;
    String siteName=null;
    if (currentStudy.getParentStudyId() > 0) {
      studyName=currentStudy.getParentStudyName();
      siteName=currentStudy.getName();
    }
 else {
      studyName=currentStudy.getName();
    }
    request.setAttribute("String_Node_Str",printCrfBeans);
    request.setAttribute("String_Node_Str",studyName);
    request.setAttribute("String_Node_Str",siteName);
    request.setAttribute("String_Node_Str",sed.getName());
    forwardPage(Page.VIEW_DEFAULT_CRF_VERSIONS_PRINT,request,response);
  }
}