Program: 115277
Project: 115277
Buggy source:
@Override public void processRequest() throws Exception {
  FormProcessor fp=new FormProcessor(request);
  locale=request.getLocale();
  request.setAttribute("String_Node_Str",true);
  String pageNumber=fp.getString(SUBJECT_PAGE_NUMBER);
  StringBuilder paginatingQuery=new StringBuilder("String_Node_Str");
  String filterKeyword=fp.getString(FILTER_KEYWORD);
  String tmpSearch=fp.getString(SEARCH_SUBMITTED);
  boolean searchSubmitted=!(tmpSearch == null || "String_Node_Str".equalsIgnoreCase(tmpSearch)) && !"String_Node_Str".equalsIgnoreCase(filterKeyword) && !"String_Node_Str".equalsIgnoreCase(filterKeyword);
  if (pageNumber != null && !"String_Node_Str".equalsIgnoreCase(pageNumber)) {
    int tempNum=0;
    try {
      tempNum=Integer.parseInt(pageNumber);
    }
 catch (    NumberFormatException nfe) {
    }
    if (tempNum > 0) {
      paginatingQuery=new StringBuilder(SUBJECT_PAGE_NUMBER).append("String_Node_Str").append(pageNumber);
      paginatingQuery.append("String_Node_Str");
    }
  }
  String filterKeywordURLEncode=java.net.URLEncoder.encode(filterKeyword,"String_Node_Str");
  if (searchSubmitted) {
    paginatingQuery.append("String_Node_Str");
    paginatingQuery.append("String_Node_Str").append(FILTER_KEYWORD).append("String_Node_Str").append(filterKeywordURLEncode);
  }
  request.setAttribute(PAGINATING_QUERY,paginatingQuery.toString());
  StudyDAO stdao=new StudyDAO(sm.getDataSource());
  StudySubjectDAO sdao=new StudySubjectDAO(sm.getDataSource());
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  SubjectGroupMapDAO sgmdao=new SubjectGroupMapDAO(sm.getDataSource());
  StudyGroupClassDAO sgcdao=new StudyGroupClassDAO(sm.getDataSource());
  StudyGroupDAO sgdao=new StudyGroupDAO(sm.getDataSource());
  StudySubjectDAO ssdao=new StudySubjectDAO(sm.getDataSource());
  int parentStudyId=currentStudy.getParentStudyId();
  ArrayList studyGroupClasses=new ArrayList();
  ArrayList allDefs=new ArrayList();
  if (parentStudyId > 0) {
    StudyBean parentStudy=(StudyBean)stdao.findByPK(parentStudyId);
    studyGroupClasses=sgcdao.findAllActiveByStudy(parentStudy);
    allDefs=seddao.findAllActiveByStudy(parentStudy);
  }
 else {
    parentStudyId=currentStudy.getId();
    studyGroupClasses=sgcdao.findAllActiveByStudy(currentStudy);
    allDefs=seddao.findAllActiveByStudy(currentStudy);
  }
  StudyParameterValueDAO spvdao=new StudyParameterValueDAO(sm.getDataSource());
  StudyParameterValueBean parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setCollectDob(parentSPV.getValue());
  parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setGenderRequired(parentSPV.getValue());
  parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setSubjectPersonIdRequired(parentSPV.getValue());
  parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
  parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setSubjectIdPrefixSuffix(parentSPV.getValue());
  for (int i=0; i < studyGroupClasses.size(); i++) {
    StudyGroupClassBean sgc=(StudyGroupClassBean)studyGroupClasses.get(i);
    ArrayList groups=sgdao.findAllByGroupClass(sgc);
    sgc.setStudyGroups(groups);
  }
  request.setAttribute("String_Node_Str",studyGroupClasses);
  session.setAttribute("String_Node_Str",allDefs);
  session.setAttribute("String_Node_Str",new Integer(allDefs.size()));
  session.setAttribute("String_Node_Str",new Integer(studyGroupClasses.size()));
  ArrayList subjects=sdao.findAllByStudyId(currentStudy.getId());
  ArrayList<DisplayStudySubjectBean> displayStudySubs=new ArrayList<DisplayStudySubjectBean>();
  for (int i=0; i < subjects.size(); i++) {
    StudySubjectBean studySub=(StudySubjectBean)subjects.get(i);
    ArrayList groups=(ArrayList)sgmdao.findAllByStudySubject(studySub.getId());
    ArrayList subGClasses=new ArrayList();
    for (int j=0; j < studyGroupClasses.size(); j++) {
      StudyGroupClassBean sgc=(StudyGroupClassBean)studyGroupClasses.get(j);
      boolean hasClass=false;
      for (int k=0; k < groups.size(); k++) {
        SubjectGroupMapBean sgmb=(SubjectGroupMapBean)groups.get(k);
        if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
          subGClasses.add(sgmb);
          hasClass=true;
          break;
        }
      }
      if (!hasClass) {
        subGClasses.add(new SubjectGroupMapBean());
      }
    }
    ArrayList subEvents=new ArrayList();
    ArrayList events=sedao.findAllByStudySubject(studySub);
    for (int j=0; j < allDefs.size(); j++) {
      StudyEventDefinitionBean sed=(StudyEventDefinitionBean)allDefs.get(j);
      boolean hasDef=false;
      for (int k=0; k < events.size(); k++) {
        StudyEventBean se=(StudyEventBean)events.get(k);
        if (se.getStudyEventDefinitionId() == sed.getId()) {
          se.setStudyEventDefinition(sed);
          subEvents.add(se);
          hasDef=true;
        }
      }
      if (!hasDef) {
        StudyEventBean blank=new StudyEventBean();
        blank.setSubjectEventStatus(SubjectEventStatus.NOT_SCHEDULED);
        blank.setStudyEventDefinitionId(sed.getId());
        blank.setStudyEventDefinition(sed);
        subEvents.add(blank);
      }
    }
    int prevDefId=0;
    int currDefId=0;
    ArrayList finalEvents=new ArrayList();
    int repeatingNum=1;
    int count=0;
    StudyEventBean event=new StudyEventBean();
    for (int j=0; j < subEvents.size(); j++) {
      StudyEventBean se=(StudyEventBean)subEvents.get(j);
      currDefId=se.getStudyEventDefinitionId();
      if (currDefId != prevDefId) {
        if (repeatingNum > 1) {
          event.setRepeatingNum(repeatingNum);
          repeatingNum=1;
        }
        finalEvents.add(se);
        event=se;
        count++;
      }
 else {
        repeatingNum++;
        event.getRepeatEvents().add(se);
        if (j == subEvents.size() - 1) {
          event.setRepeatingNum(repeatingNum);
          repeatingNum=1;
        }
      }
      prevDefId=currDefId;
    }
    DisplayStudySubjectBean dssb=new DisplayStudySubjectBean();
    dssb.setStudyEvents(finalEvents);
    dssb.setStudySubject(studySub);
    dssb.setStudyGroups(subGClasses);
    displayStudySubs.add(dssb);
  }
  boolean isRequiredUncomplete=false;
  for (  DisplayStudySubjectBean subject : displayStudySubs) {
    for (Iterator it=subject.getStudyEvents().iterator(); it.hasNext(); ) {
      StudyEventBean event=(StudyEventBean)it.next();
      if (event.getSubjectEventStatus() != null && event.getSubjectEventStatus().getId() == 3) {
        subject.setStudySignable(false);
        break;
      }
 else {
        isRequiredUncomplete=eventHasRequiredUncompleteCRFs(event);
        if (isRequiredUncomplete) {
          subject.setStudySignable(false);
          break;
        }
      }
    }
  }
  fp=new FormProcessor(request);
  EntityBeanTable table=fp.getEntityBeanTable();
  ArrayList allStudyRows=DisplayStudySubjectRow.generateRowsFromBeans(displayStudySubs);
  ArrayList columnArray=new ArrayList();
  columnArray.add(resword.getString("String_Node_Str"));
  columnArray.add(resword.getString("String_Node_Str"));
  columnArray.add(resword.getString("String_Node_Str"));
  columnArray.add(resword.getString("String_Node_Str"));
  columnArray.add(resword.getString("String_Node_Str"));
  for (int i=0; i < studyGroupClasses.size(); i++) {
    StudyGroupClassBean sgc=(StudyGroupClassBean)studyGroupClasses.get(i);
    columnArray.add(sgc.getName());
  }
  for (int i=0; i < allDefs.size(); i++) {
    StudyEventDefinitionBean sed=(StudyEventDefinitionBean)allDefs.get(i);
    columnArray.add(sed.getName());
  }
  columnArray.add(resword.getString("String_Node_Str"));
  String columns[]=new String[columnArray.size()];
  columnArray.toArray(columns);
  table.setColumns(new ArrayList(Arrays.asList(columns)));
  table.setQuery(getBaseURL(),new HashMap());
  table.hideColumnLink(columnArray.size() - 1);
  table.setRows(allStudyRows);
  if (filterKeyword != null && !"String_Node_Str".equalsIgnoreCase(filterKeyword)) {
    table.setKeywordFilter(filterKeyword);
  }
  table.computeDisplay();
  request.setAttribute("String_Node_Str",table);
  String idSetting=currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
  if (idSetting.equals("String_Node_Str") || idSetting.equals("String_Node_Str")) {
    request.setAttribute("String_Node_Str",AUTO_LABEL);
  }
  FormDiscrepancyNotes discNotes=new FormDiscrepancyNotes();
  session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
  forwardPage(getJSP());
}

Fixed version (ground truth):
@Override public void processRequest() throws Exception {
  FormProcessor fp=new FormProcessor(request);
  locale=request.getLocale();
  request.setAttribute("String_Node_Str",true);
  String pageNumber=fp.getString(SUBJECT_PAGE_NUMBER);
  StringBuilder paginatingQuery=new StringBuilder("String_Node_Str");
  String filterKeyword=fp.getString(FILTER_KEYWORD);
  String tmpSearch=fp.getString(SEARCH_SUBMITTED);
  boolean searchSubmitted=!(tmpSearch == null || "String_Node_Str".equalsIgnoreCase(tmpSearch)) && !"String_Node_Str".equalsIgnoreCase(filterKeyword) && !"String_Node_Str".equalsIgnoreCase(filterKeyword);
  if (pageNumber != null && !"String_Node_Str".equalsIgnoreCase(pageNumber)) {
    int tempNum=0;
    try {
      tempNum=Integer.parseInt(pageNumber);
    }
 catch (    NumberFormatException nfe) {
    }
    if (tempNum > 0) {
      paginatingQuery=new StringBuilder(SUBJECT_PAGE_NUMBER).append("String_Node_Str").append(pageNumber);
      paginatingQuery.append("String_Node_Str");
    }
  }
  String filterKeywordURLEncode=java.net.URLEncoder.encode(filterKeyword,"String_Node_Str");
  if (searchSubmitted) {
    paginatingQuery.append("String_Node_Str");
    paginatingQuery.append("String_Node_Str").append(FILTER_KEYWORD).append("String_Node_Str").append(filterKeywordURLEncode);
  }
  request.setAttribute(PAGINATING_QUERY,paginatingQuery.toString());
  StudyDAO stdao=new StudyDAO(sm.getDataSource());
  StudySubjectDAO sdao=new StudySubjectDAO(sm.getDataSource());
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  SubjectGroupMapDAO sgmdao=new SubjectGroupMapDAO(sm.getDataSource());
  StudyGroupClassDAO sgcdao=new StudyGroupClassDAO(sm.getDataSource());
  StudyGroupDAO sgdao=new StudyGroupDAO(sm.getDataSource());
  StudySubjectDAO ssdao=new StudySubjectDAO(sm.getDataSource());
  int parentStudyId=currentStudy.getParentStudyId();
  ArrayList studyGroupClasses=new ArrayList();
  ArrayList allDefs=new ArrayList();
  if (parentStudyId > 0) {
    StudyBean parentStudy=(StudyBean)stdao.findByPK(parentStudyId);
    studyGroupClasses=sgcdao.findAllActiveByStudy(parentStudy);
    allDefs=seddao.findAllActiveByStudy(parentStudy);
  }
 else {
    parentStudyId=currentStudy.getId();
    studyGroupClasses=sgcdao.findAllActiveByStudy(currentStudy);
    allDefs=seddao.findAllActiveByStudy(currentStudy);
  }
  StudyParameterValueDAO spvdao=new StudyParameterValueDAO(sm.getDataSource());
  StudyParameterValueBean parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setCollectDob(parentSPV.getValue());
  parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setGenderRequired(parentSPV.getValue());
  parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setSubjectPersonIdRequired(parentSPV.getValue());
  parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
  parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  currentStudy.getStudyParameterConfig().setSubjectIdPrefixSuffix(parentSPV.getValue());
  for (int i=0; i < studyGroupClasses.size(); i++) {
    StudyGroupClassBean sgc=(StudyGroupClassBean)studyGroupClasses.get(i);
    ArrayList groups=sgdao.findAllByGroupClass(sgc);
    sgc.setStudyGroups(groups);
  }
  request.setAttribute("String_Node_Str",studyGroupClasses);
  session.setAttribute("String_Node_Str",allDefs);
  session.setAttribute("String_Node_Str",new Integer(allDefs.size()));
  session.setAttribute("String_Node_Str",new Integer(studyGroupClasses.size()));
  ArrayList subjects=sdao.findAllByStudyId(currentStudy.getId());
  ArrayList<DisplayStudySubjectBean> displayStudySubs=new ArrayList<DisplayStudySubjectBean>();
  for (int i=0; i < subjects.size(); i++) {
    StudySubjectBean studySub=(StudySubjectBean)subjects.get(i);
    ArrayList groups=(ArrayList)sgmdao.findAllByStudySubject(studySub.getId());
    ArrayList subGClasses=new ArrayList();
    for (int j=0; j < studyGroupClasses.size(); j++) {
      StudyGroupClassBean sgc=(StudyGroupClassBean)studyGroupClasses.get(j);
      boolean hasClass=false;
      for (int k=0; k < groups.size(); k++) {
        SubjectGroupMapBean sgmb=(SubjectGroupMapBean)groups.get(k);
        if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
          subGClasses.add(sgmb);
          hasClass=true;
          break;
        }
      }
      if (!hasClass) {
        subGClasses.add(new SubjectGroupMapBean());
      }
    }
    ArrayList subEvents=new ArrayList();
    ArrayList events=sedao.findAllByStudySubject(studySub);
    for (int j=0; j < allDefs.size(); j++) {
      StudyEventDefinitionBean sed=(StudyEventDefinitionBean)allDefs.get(j);
      boolean hasDef=false;
      for (int k=0; k < events.size(); k++) {
        StudyEventBean se=(StudyEventBean)events.get(k);
        if (se.getStudyEventDefinitionId() == sed.getId()) {
          se.setStudyEventDefinition(sed);
          subEvents.add(se);
          hasDef=true;
        }
      }
      if (!hasDef) {
        StudyEventBean blank=new StudyEventBean();
        blank.setSubjectEventStatus(SubjectEventStatus.NOT_SCHEDULED);
        blank.setStudyEventDefinitionId(sed.getId());
        blank.setStudyEventDefinition(sed);
        subEvents.add(blank);
      }
    }
    int prevDefId=0;
    int currDefId=0;
    ArrayList finalEvents=new ArrayList();
    int repeatingNum=1;
    int count=0;
    StudyEventBean event=new StudyEventBean();
    for (int j=0; j < subEvents.size(); j++) {
      StudyEventBean se=(StudyEventBean)subEvents.get(j);
      currDefId=se.getStudyEventDefinitionId();
      if (currDefId != prevDefId) {
        if (repeatingNum > 1) {
          event.setRepeatingNum(repeatingNum);
          repeatingNum=1;
        }
        finalEvents.add(se);
        event=se;
        count++;
      }
 else {
        repeatingNum++;
        event.getRepeatEvents().add(se);
        if (j == subEvents.size() - 1) {
          event.setRepeatingNum(repeatingNum);
          repeatingNum=1;
        }
      }
      prevDefId=currDefId;
    }
    DisplayStudySubjectBean dssb=new DisplayStudySubjectBean();
    dssb.setStudyEvents(finalEvents);
    dssb.setStudySubject(studySub);
    dssb.setStudyGroups(subGClasses);
    displayStudySubs.add(dssb);
  }
  boolean isRequiredUncomplete=false;
  for (  DisplayStudySubjectBean subject : displayStudySubs) {
    for (Iterator it=subject.getStudyEvents().iterator(); it.hasNext(); ) {
      StudyEventBean event=(StudyEventBean)it.next();
      if (event.getSubjectEventStatus() != null && event.getSubjectEventStatus().getId() == 3) {
        subject.setStudySignable(false);
        break;
      }
 else {
        isRequiredUncomplete=eventHasRequiredUncompleteCRFs(event);
        if (isRequiredUncomplete) {
          subject.setStudySignable(false);
          break;
        }
      }
    }
  }
  fp=new FormProcessor(request);
  EntityBeanTable table=fp.getEntityBeanTable();
  ArrayList allStudyRows=DisplayStudySubjectRow.generateRowsFromBeans(displayStudySubs);
  ArrayList columnArray=new ArrayList();
  columnArray.add(resword.getString("String_Node_Str"));
  columnArray.add(resword.getString("String_Node_Str"));
  columnArray.add(resword.getString("String_Node_Str"));
  columnArray.add(resword.getString("String_Node_Str"));
  columnArray.add(resword.getString("String_Node_Str"));
  for (int i=0; i < studyGroupClasses.size(); i++) {
    StudyGroupClassBean sgc=(StudyGroupClassBean)studyGroupClasses.get(i);
    columnArray.add(sgc.getName());
  }
  for (int i=0; i < allDefs.size(); i++) {
    StudyEventDefinitionBean sed=(StudyEventDefinitionBean)allDefs.get(i);
    columnArray.add(sed.getName());
  }
  columnArray.add(resword.getString("String_Node_Str"));
  String columns[]=new String[columnArray.size()];
  columnArray.toArray(columns);
  table.setColumns(new ArrayList(Arrays.asList(columns)));
  table.setQuery(getBaseURL(),new HashMap());
  table.hideColumnLink(columnArray.size() - 1);
  table.setRows(allStudyRows);
  if (filterKeyword != null && !"String_Node_Str".equalsIgnoreCase(filterKeyword)) {
    table.setKeywordFilter(filterKeyword);
  }
  table.computeDisplay();
  request.setAttribute("String_Node_Str",table);
  String idSetting=currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
  if (idSetting.equals("String_Node_Str") || idSetting.equals("String_Node_Str")) {
    request.setAttribute("String_Node_Str",resword.getString("String_Node_Str"));
  }
  FormDiscrepancyNotes discNotes=new FormDiscrepancyNotes();
  session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
  forwardPage(getJSP());
}