Program: 115186
Project: 115186
Buggy source:
private void changeStudy() throws Exception {
  Validator v=new Validator(request);
  FormProcessor fp=new FormProcessor(request);
  int studyId=fp.getInt("String_Node_Str");
  int prevStudyId=currentStudy.getId();
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  StudyBean current=(StudyBean)sdao.findByPK(studyId);
  StudyParameterValueDAO spvdao=new StudyParameterValueDAO(sm.getDataSource());
  ArrayList studyParameters=spvdao.findParamConfigByStudy(current);
  current.setStudyParameters(studyParameters);
  int parentStudyId=currentStudy.getParentStudyId() > 0 ? currentStudy.getParentStudyId() : currentStudy.getId();
  StudyParameterValueBean parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  current.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
  String idSetting=current.getStudyParameterConfig().getSubjectIdGeneration();
  if (idSetting.equals("String_Node_Str") || idSetting.equals("String_Node_Str")) {
    int nextLabel=this.getStudySubjectDAO().findTheGreatestLabel() + 1;
    request.setAttribute("String_Node_Str",new Integer(nextLabel).toString());
  }
  StudyConfigService scs=new StudyConfigService(sm.getDataSource());
  if (current.getParentStudyId() <= 0) {
    scs.setParametersForStudy(current);
  }
 else {
    if (current.getParentStudyId() > 0) {
      current.setParentStudyName(((StudyBean)sdao.findByPK(current.getParentStudyId())).getName());
    }
    scs.setParametersForSite(current);
  }
  if (current.getStatus().equals(Status.DELETED) || current.getStatus().equals(Status.AUTO_DELETED)) {
    session.removeAttribute("String_Node_Str");
    addPageMessage(restext.getString("String_Node_Str"));
  }
 else {
    session.setAttribute("String_Node_Str",current);
    currentStudy=current;
    UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
    ub.setActiveStudyId(current.getId());
    ub.setUpdater(ub);
    ub.setUpdatedDate(new java.util.Date());
    udao.update(ub);
    if (current.getParentStudyId() > 0) {
      List roles=Role.toArrayList();
      for (Iterator it=roles.iterator(); it.hasNext(); ) {
        Role role=(Role)it.next();
switch (role.getId()) {
case 2:
          role.setDescription("String_Node_Str");
        break;
case 3:
      role.setDescription("String_Node_Str");
    break;
case 4:
  role.setDescription("String_Node_Str");
break;
case 5:
role.setDescription("String_Node_Str");
break;
case 6:
role.setDescription("String_Node_Str");
break;
default :
logger.info("String_Node_Str");
}
}
}
 else {
List roles=Role.toArrayList();
for (Iterator it=roles.iterator(); it.hasNext(); ) {
Role role=(Role)it.next();
switch (role.getId()) {
case 2:
role.setDescription("String_Node_Str");
break;
case 3:
role.setDescription("String_Node_Str");
break;
case 4:
role.setDescription("String_Node_Str");
break;
case 5:
role.setDescription("String_Node_Str");
break;
case 6:
role.setDescription("String_Node_Str");
break;
default :
logger.info("String_Node_Str");
}
}
}
currentRole=(StudyUserRoleBean)session.getAttribute("String_Node_Str");
session.setAttribute("String_Node_Str",currentRole);
session.removeAttribute("String_Node_Str");
addPageMessage(restext.getString("String_Node_Str"));
}
ub.incNumVisitsToMainMenu();
if (prevStudyId != studyId) {
session.removeAttribute("String_Node_Str");
}
request.setAttribute("String_Node_Str","String_Node_Str");
Integer assignedDiscrepancies=getDiscrepancyNoteDAO().getViewNotesCountWithFilter("String_Node_Str" + ub.getId() + "String_Node_Str",currentStudy);
request.setAttribute("String_Node_Str",assignedDiscrepancies == null ? 0 : assignedDiscrepancies);
if (currentRole.isInvestigator() || currentRole.isResearchAssistant()) {
setupListStudySubjectTable();
}
if (currentRole.isMonitor()) {
setupSubjectSDVTable();
}
 else if (currentRole.isCoordinator() || currentRole.isDirector()) {
if (currentStudy.getStatus().isPending()) {
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE);
return;
}
setupStudySiteStatisticsTable();
setupSubjectEventStatusStatisticsTable();
setupStudySubjectStatusStatisticsTable();
if (currentStudy.getParentStudyId() == 0) {
setupStudyStatisticsTable();
}
}
forwardPage(Page.MENU);
}

Fixed version (ground truth):
private void changeStudy() throws Exception {
  Validator v=new Validator(request);
  FormProcessor fp=new FormProcessor(request);
  int studyId=fp.getInt("String_Node_Str");
  int prevStudyId=currentStudy.getId();
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  StudyBean current=(StudyBean)sdao.findByPK(studyId);
  StudyParameterValueDAO spvdao=new StudyParameterValueDAO(sm.getDataSource());
  ArrayList studyParameters=spvdao.findParamConfigByStudy(current);
  current.setStudyParameters(studyParameters);
  int parentStudyId=currentStudy.getParentStudyId() > 0 ? currentStudy.getParentStudyId() : currentStudy.getId();
  StudyParameterValueBean parentSPV=spvdao.findByHandleAndStudy(parentStudyId,"String_Node_Str");
  current.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
  String idSetting=current.getStudyParameterConfig().getSubjectIdGeneration();
  if (idSetting.equals("String_Node_Str") || idSetting.equals("String_Node_Str")) {
    int nextLabel=this.getStudySubjectDAO().findTheGreatestLabel() + 1;
    request.setAttribute("String_Node_Str",new Integer(nextLabel).toString());
  }
  StudyConfigService scs=new StudyConfigService(sm.getDataSource());
  if (current.getParentStudyId() <= 0) {
    scs.setParametersForStudy(current);
  }
 else {
    if (current.getParentStudyId() > 0) {
      current.setParentStudyName(((StudyBean)sdao.findByPK(current.getParentStudyId())).getName());
    }
    scs.setParametersForSite(current);
  }
  if (current.getStatus().equals(Status.DELETED) || current.getStatus().equals(Status.AUTO_DELETED)) {
    session.removeAttribute("String_Node_Str");
    addPageMessage(restext.getString("String_Node_Str"));
  }
 else {
    session.setAttribute("String_Node_Str",current);
    currentStudy=current;
    UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
    ub.setActiveStudyId(current.getId());
    ub.setUpdater(ub);
    ub.setUpdatedDate(new java.util.Date());
    udao.update(ub);
    if (current.getParentStudyId() > 0) {
      List roles=Role.toArrayList();
      for (Iterator it=roles.iterator(); it.hasNext(); ) {
        Role role=(Role)it.next();
switch (role.getId()) {
case 2:
          role.setDescription("String_Node_Str");
        break;
case 3:
      role.setDescription("String_Node_Str");
    break;
case 4:
  role.setDescription("String_Node_Str");
break;
case 5:
role.setDescription("String_Node_Str");
break;
case 6:
role.setDescription("String_Node_Str");
break;
default :
}
}
}
 else {
List roles=Role.toArrayList();
for (Iterator it=roles.iterator(); it.hasNext(); ) {
Role role=(Role)it.next();
switch (role.getId()) {
case 2:
role.setDescription("String_Node_Str");
break;
case 3:
role.setDescription("String_Node_Str");
break;
case 4:
role.setDescription("String_Node_Str");
break;
case 5:
role.setDescription("String_Node_Str");
break;
case 6:
role.setDescription("String_Node_Str");
break;
default :
}
}
}
currentRole=(StudyUserRoleBean)session.getAttribute("String_Node_Str");
session.setAttribute("String_Node_Str",currentRole);
session.removeAttribute("String_Node_Str");
addPageMessage(restext.getString("String_Node_Str"));
}
ub.incNumVisitsToMainMenu();
if (prevStudyId != studyId) {
session.removeAttribute("String_Node_Str");
}
request.setAttribute("String_Node_Str","String_Node_Str");
Integer assignedDiscrepancies=getDiscrepancyNoteDAO().getViewNotesCountWithFilter("String_Node_Str" + ub.getId() + "String_Node_Str",currentStudy);
request.setAttribute("String_Node_Str",assignedDiscrepancies == null ? 0 : assignedDiscrepancies);
if (currentRole.isInvestigator() || currentRole.isResearchAssistant()) {
setupListStudySubjectTable();
}
if (currentRole.isMonitor()) {
setupSubjectSDVTable();
}
 else if (currentRole.isCoordinator() || currentRole.isDirector()) {
if (currentStudy.getStatus().isPending()) {
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE);
return;
}
setupStudySiteStatisticsTable();
setupSubjectEventStatusStatisticsTable();
setupStudySubjectStatusStatisticsTable();
if (currentStudy.getParentStudyId() == 0) {
setupStudyStatisticsTable();
}
}
forwardPage(Page.MENU);
}