Program: 115011
Project: 115011
Buggy source:
private void changeStudy() throws Exception {
  Validator v=new Validator(request);
  FormProcessor fp=new FormProcessor(request);
  String studySchema=fp.getString("String_Node_Str",true);
  request.setAttribute("String_Node_Str","String_Node_Str");
  String studyEnvUuid=fp.getString("String_Node_Str",true);
  String prevStudyEnvUuid=currentStudy != null ? currentStudy.getStudyEnvUuid() : null;
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  StudyBean current=sdao.findByStudyEnvUuid(studyEnvUuid);
  StudyParameterValueDAO spvdao=new StudyParameterValueDAO(sm.getDataSource());
  ArrayList studyParameters=spvdao.findParamConfigByStudy(current);
  current.setStudyParameters(studyParameters);
  if (currentStudy != null) {
    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((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);
    currentPublicStudy=current;
    UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
    ub.setActiveStudyId(current.getId());
    ub.setUpdater(ub);
    ub.setUpdatedDate(new java.util.Date());
    udao.update(ub);
    request.setAttribute("String_Node_Str",studySchema);
    StudyDAO sdaoStudy=new StudyDAO(sm.getDataSource());
    StudyBean study=sdaoStudy.findByStudyEnvUuid(studyEnvUuid);
    session.setAttribute("String_Node_Str",study);
    currentStudy=study;
    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;
case 7:
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 (StringUtils.equals(prevStudyEnvUuid,studyEnvUuid) != true) {
session.removeAttribute("String_Node_Str");
session.setAttribute("String_Node_Str","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() || currentRole.isResearchAssistant2()) {
setupListStudySubjectTable();
}
if (currentRole.isMonitor()) {
setupSubjectSDVTable();
}
 else if (currentRole.isCoordinator() || currentRole.isDirector()) {
if (currentStudy.getStatus().isPending()) {
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
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);
  String studySchema=fp.getString("String_Node_Str",true);
  request.setAttribute("String_Node_Str","String_Node_Str");
  String studyEnvUuid=fp.getString("String_Node_Str",true);
  String prevStudyEnvUuid=currentStudy != null ? currentStudy.getStudyEnvUuid() : null;
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  StudyBean current=sdao.findByStudyEnvUuid(studyEnvUuid);
  StudyParameterValueDAO spvdao=new StudyParameterValueDAO(sm.getDataSource());
  ArrayList studyParameters=spvdao.findParamConfigByStudy(current);
  current.setStudyParameters(studyParameters);
  if (currentStudy != null) {
    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((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);
    currentPublicStudy=current;
    UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
    ub.setActiveStudyId(current.getId());
    ub.setUpdater(ub);
    ub.setUpdatedDate(new java.util.Date());
    udao.update(ub);
    request.setAttribute("String_Node_Str",studySchema);
    StudyDAO sdaoStudy=new StudyDAO(sm.getDataSource());
    StudyBean study=sdaoStudy.findByStudyEnvUuid(studyEnvUuid);
    study.setParentStudyName(currentPublicStudy.getParentStudyName());
    session.setAttribute("String_Node_Str",study);
    currentStudy=study;
    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;
case 7:
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 (StringUtils.equals(prevStudyEnvUuid,studyEnvUuid) != true) {
session.removeAttribute("String_Node_Str");
session.setAttribute("String_Node_Str","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() || currentRole.isResearchAssistant2()) {
setupListStudySubjectTable();
}
if (currentRole.isMonitor()) {
setupSubjectSDVTable();
}
 else if (currentRole.isCoordinator() || currentRole.isDirector()) {
if (currentStudy.getStatus().isPending()) {
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
return;
}
setupStudySiteStatisticsTable();
setupSubjectEventStatusStatisticsTable();
setupStudySubjectStatusStatisticsTable();
if (currentStudy.getParentStudyId() == 0) {
setupStudyStatisticsTable();
}
}
forwardPage(Page.MENU);
}