Program: 115354
Project: 115354
Buggy source:
@Override public void processRequest() throws Exception {
  FormDiscrepancyNotes discNotes=null;
  SubjectDAO sdao=new SubjectDAO(sm.getDataSource());
  StudySubjectDAO subdao=new StudySubjectDAO(sm.getDataSource());
  FormProcessor fp=new FormProcessor(request);
  String fromResolvingNotes=fp.getString("String_Node_Str",true);
  if (StringUtil.isBlank(fromResolvingNotes)) {
    session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
    session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
    checkStudyLocked(Page.LIST_STUDY_SUBJECTS_SERVLET,respage.getString("String_Node_Str"));
    checkStudyFrozen(Page.LIST_STUDY_SUBJECTS_SERVLET,respage.getString("String_Node_Str"));
  }
  int studySubId=fp.getInt("String_Node_Str",true);
  if (studySubId == 0) {
    addPageMessage(respage.getString("String_Node_Str"));
    forwardPage(Page.LIST_STUDY_SUBJECTS);
  }
 else {
    String action=fp.getString("String_Node_Str",true);
    if (StringUtil.isBlank(action)) {
      addPageMessage(respage.getString("String_Node_Str"));
      forwardPage(Page.LIST_STUDY_SUBJECTS);
      return;
    }
    StudySubjectBean sub=(StudySubjectBean)subdao.findByPK(studySubId);
    StudyGroupClassDAO sgcdao=new StudyGroupClassDAO(sm.getDataSource());
    StudyGroupDAO sgdao=new StudyGroupDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao=new SubjectGroupMapDAO(sm.getDataSource());
    ArrayList groupMaps=(ArrayList)sgmdao.findAllByStudySubject(studySubId);
    HashMap gMaps=new HashMap();
    for (int i=0; i < groupMaps.size(); i++) {
      SubjectGroupMapBean groupMap=(SubjectGroupMapBean)groupMaps.get(i);
      gMaps.put(new Integer(groupMap.getStudyGroupClassId()),groupMap);
    }
    StudyDAO stdao=new StudyDAO(sm.getDataSource());
    ArrayList classes=new ArrayList();
    if (!"String_Node_Str".equalsIgnoreCase(action)) {
      int parentStudyId=currentStudy.getParentStudyId();
      if (parentStudyId > 0) {
        StudyBean parentStudy=(StudyBean)stdao.findByPK(parentStudyId);
        classes=sgcdao.findAllActiveByStudy(parentStudy);
      }
 else {
        classes=sgcdao.findAllActiveByStudy(currentStudy);
      }
      for (int i=0; i < classes.size(); i++) {
        StudyGroupClassBean group=(StudyGroupClassBean)classes.get(i);
        ArrayList studyGroups=sgdao.findAllByGroupClass(group);
        group.setStudyGroups(studyGroups);
        SubjectGroupMapBean gMap=(SubjectGroupMapBean)gMaps.get(new Integer(group.getId()));
        if (gMap != null) {
          group.setStudyGroupId(gMap.getStudyGroupId());
          group.setGroupNotes(gMap.getNotes());
        }
      }
      session.setAttribute("String_Node_Str",classes);
    }
    if ("String_Node_Str".equalsIgnoreCase(action)) {
      session.setAttribute("String_Node_Str",sub);
      String enrollDateStr=local_df.format(sub.getEnrollmentDate());
      session.setAttribute("String_Node_Str",enrollDateStr);
      discNotes=new FormDiscrepancyNotes();
      session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
      forwardPage(Page.UPDATE_STUDY_SUBJECT);
    }
 else     if ("String_Node_Str".equalsIgnoreCase(action)) {
      confirm(sgdao);
    }
 else     if ("String_Node_Str".equalsIgnoreCase(action)) {
      StudySubjectBean subject=(StudySubjectBean)session.getAttribute("String_Node_Str");
      subject.setUpdater(ub);
      subdao.update(subject);
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
      AddNewSubjectServlet.saveFieldNotes("String_Node_Str",fdn,dndao,subject.getId(),"String_Node_Str",currentStudy);
      ArrayList groups=(ArrayList)session.getAttribute("String_Node_Str");
      if (!groups.isEmpty()) {
        for (int i=0; i < groups.size(); i++) {
          StudyGroupClassBean sgc=(StudyGroupClassBean)groups.get(i);
          SubjectGroupMapBean sgm=new SubjectGroupMapBean();
          SubjectGroupMapBean gMap=(SubjectGroupMapBean)gMaps.get(new Integer(sgc.getId()));
          sgm.setStudyGroupId(sgc.getStudyGroupId());
          sgm.setNotes(sgc.getGroupNotes());
          sgm.setStudyGroupClassId(sgc.getId());
          sgm.setStudySubjectId(subject.getId());
          sgm.setStatus(Status.AVAILABLE);
          if (sgm.getStudyGroupId() > 0) {
            if (gMap != null && gMap.getId() > 0) {
              sgm.setUpdater(ub);
              sgm.setId(gMap.getId());
              sgmdao.update(sgm);
            }
 else {
              sgm.setOwner(ub);
              sgmdao.create(sgm);
            }
          }
        }
      }
      addPageMessage(respage.getString("String_Node_Str"));
      session.removeAttribute("String_Node_Str");
      session.removeAttribute("String_Node_Str");
      session.removeAttribute("String_Node_Str");
      session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      request.setAttribute("String_Node_Str",new Integer(studySubId).toString());
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
 else {
      addPageMessage(respage.getString("String_Node_Str"));
      forwardPage(Page.LIST_STUDY_SUBJECTS);
      return;
    }
  }
}

Fixed version (ground truth):
@Override public void processRequest() throws Exception {
  FormDiscrepancyNotes discNotes=null;
  SubjectDAO sdao=new SubjectDAO(sm.getDataSource());
  StudySubjectDAO subdao=new StudySubjectDAO(sm.getDataSource());
  FormProcessor fp=new FormProcessor(request);
  String fromResolvingNotes=fp.getString("String_Node_Str",true);
  if (StringUtil.isBlank(fromResolvingNotes)) {
    session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
    session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
    checkStudyLocked(Page.LIST_STUDY_SUBJECTS_SERVLET,respage.getString("String_Node_Str"));
    checkStudyFrozen(Page.LIST_STUDY_SUBJECTS_SERVLET,respage.getString("String_Node_Str"));
  }
  int studySubId=fp.getInt("String_Node_Str",true);
  if (studySubId == 0) {
    addPageMessage(respage.getString("String_Node_Str"));
    forwardPage(Page.LIST_STUDY_SUBJECTS);
  }
 else {
    String action=fp.getString("String_Node_Str",true);
    if (StringUtil.isBlank(action)) {
      addPageMessage(respage.getString("String_Node_Str"));
      forwardPage(Page.LIST_STUDY_SUBJECTS);
      return;
    }
    StudySubjectBean sub=(StudySubjectBean)subdao.findByPK(studySubId);
    StudyGroupClassDAO sgcdao=new StudyGroupClassDAO(sm.getDataSource());
    StudyGroupDAO sgdao=new StudyGroupDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao=new SubjectGroupMapDAO(sm.getDataSource());
    ArrayList groupMaps=(ArrayList)sgmdao.findAllByStudySubject(studySubId);
    HashMap gMaps=new HashMap();
    for (int i=0; i < groupMaps.size(); i++) {
      SubjectGroupMapBean groupMap=(SubjectGroupMapBean)groupMaps.get(i);
      gMaps.put(new Integer(groupMap.getStudyGroupClassId()),groupMap);
    }
    StudyDAO stdao=new StudyDAO(sm.getDataSource());
    ArrayList classes=new ArrayList();
    if (!"String_Node_Str".equalsIgnoreCase(action)) {
      int parentStudyId=currentStudy.getParentStudyId();
      if (parentStudyId > 0) {
        StudyBean parentStudy=(StudyBean)stdao.findByPK(parentStudyId);
        classes=sgcdao.findAllActiveByStudy(parentStudy);
      }
 else {
        classes=sgcdao.findAllActiveByStudy(currentStudy);
      }
      for (int i=0; i < classes.size(); i++) {
        StudyGroupClassBean group=(StudyGroupClassBean)classes.get(i);
        ArrayList studyGroups=sgdao.findAllByGroupClass(group);
        group.setStudyGroups(studyGroups);
        SubjectGroupMapBean gMap=(SubjectGroupMapBean)gMaps.get(new Integer(group.getId()));
        if (gMap != null) {
          group.setStudyGroupId(gMap.getStudyGroupId());
          group.setGroupNotes(gMap.getNotes());
        }
      }
      session.setAttribute("String_Node_Str",classes);
    }
    if ("String_Node_Str".equalsIgnoreCase(action)) {
      session.setAttribute("String_Node_Str",sub);
      String enrollDateStr=local_df.format(sub.getEnrollmentDate());
      session.setAttribute("String_Node_Str",enrollDateStr);
      discNotes=new FormDiscrepancyNotes();
      session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
      forwardPage(Page.UPDATE_STUDY_SUBJECT);
    }
 else     if ("String_Node_Str".equalsIgnoreCase(action)) {
      confirm(sgdao);
    }
 else     if ("String_Node_Str".equalsIgnoreCase(action)) {
      StudySubjectBean subject=(StudySubjectBean)session.getAttribute("String_Node_Str");
      subject.setUpdater(ub);
      subdao.update(subject);
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
      AddNewSubjectServlet.saveFieldNotes("String_Node_Str",fdn,dndao,subject.getId(),"String_Node_Str",currentStudy);
      ArrayList groups=(ArrayList)session.getAttribute("String_Node_Str");
      if (!groups.isEmpty()) {
        for (int i=0; i < groups.size(); i++) {
          StudyGroupClassBean sgc=(StudyGroupClassBean)groups.get(i);
          if (sgc.getStudyGroupId() == 0) {
            Collection subjectGroups=sgmdao.findAllByStudySubject(subject.getId());
            for (Iterator it=subjectGroups.iterator(); it.hasNext(); ) {
              sgmdao.deleteTestGroupMap(((SubjectGroupMapBean)it.next()).getId());
            }
          }
 else {
            SubjectGroupMapBean sgm=new SubjectGroupMapBean();
            SubjectGroupMapBean gMap=(SubjectGroupMapBean)gMaps.get(new Integer(sgc.getId()));
            sgm.setStudyGroupId(sgc.getStudyGroupId());
            sgm.setNotes(sgc.getGroupNotes());
            sgm.setStudyGroupClassId(sgc.getId());
            sgm.setStudySubjectId(subject.getId());
            sgm.setStatus(Status.AVAILABLE);
            if (sgm.getStudyGroupId() > 0) {
              if (gMap != null && gMap.getId() > 0) {
                sgm.setUpdater(ub);
                sgm.setId(gMap.getId());
                sgmdao.update(sgm);
              }
 else {
                sgm.setOwner(ub);
                sgmdao.create(sgm);
              }
            }
          }
        }
      }
      addPageMessage(respage.getString("String_Node_Str"));
      session.removeAttribute("String_Node_Str");
      session.removeAttribute("String_Node_Str");
      session.removeAttribute("String_Node_Str");
      session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      request.setAttribute("String_Node_Str",new Integer(studySubId).toString());
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
 else {
      addPageMessage(respage.getString("String_Node_Str"));
      forwardPage(Page.LIST_STUDY_SUBJECTS);
      return;
    }
  }
}