Program: 115189
Project: 115189
Buggy source:
@Override protected void processRequest() throws Exception {
  UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
  FormProcessor fp=new FormProcessor(request);
  int studyId=fp.getInt(ARG_STUDY_ID);
  String uName=fp.getString(ARG_USER_NAME);
  StudyUserRoleBean studyUserRole=udao.findRoleByUserNameAndStudyId(uName,studyId);
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  StudyBean sb=(StudyBean)sdao.findByPK(studyUserRole.getStudyId());
  if (sb != null) {
    studyUserRole.setStudyName(sb.getName());
  }
  if (!studyUserRole.isActive()) {
    String message=respage.getString("String_Node_Str");
    addPageMessage(message);
    forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
  }
 else {
    Map roleMap=new LinkedHashMap();
    for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
      Role role=(Role)it.next();
      roleMap.put(role.getId(),role.getDescription());
    }
    roleMap=new LinkedHashMap();
    ResourceBundle resterm=org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
    StudyBean study=(StudyBean)sdao.findByPK(studyUserRole.getStudyId());
    if (study.getParentStudyId() == 0) {
      for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
        Role role=(Role)it.next();
switch (role.getId()) {
case 2:
          roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
        break;
case 3:
      roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
    break;
case 4:
  roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
case 5:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
case 6:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
default :
logger.info("String_Node_Str");
}
}
}
 else {
for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
Role role=(Role)it.next();
switch (role.getId()) {
case 4:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
case 5:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
case 6:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
default :
logger.info("String_Node_Str");
}
}
}
if (study.getParentStudyId() > 0) {
roleMap.remove(Role.COORDINATOR.getId());
roleMap.remove(Role.STUDYDIRECTOR.getId());
}
if (!fp.isSubmitted()) {
request.setAttribute("String_Node_Str",uName);
request.setAttribute("String_Node_Str",studyUserRole);
request.setAttribute("String_Node_Str",roleMap);
request.setAttribute("String_Node_Str",new Integer(studyUserRole.getRole().getId()));
forwardPage(Page.EDIT_STUDY_USER_ROLE);
}
 else {
Validator v=new Validator(request);
v.addValidation(INPUT_ROLE,Validator.IS_VALID_TERM,TermType.ROLE);
HashMap errors=v.validate();
if (errors.isEmpty()) {
int roleId=fp.getInt(INPUT_ROLE);
Role r=Role.get(roleId);
studyUserRole.setRoleName(r.getName());
studyUserRole.setUpdater(ub);
udao.updateStudyUserRole(studyUserRole,uName);
String message=respage.getString("String_Node_Str");
addPageMessage(message);
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
 else {
String message=respage.getString("String_Node_Str");
addPageMessage(message);
request.setAttribute("String_Node_Str",uName);
request.setAttribute("String_Node_Str",studyUserRole);
request.setAttribute("String_Node_Str",new Integer(fp.getInt(INPUT_ROLE)));
request.setAttribute("String_Node_Str",roleMap);
forwardPage(Page.EDIT_STUDY_USER_ROLE);
}
}
}
}

Fixed version (ground truth):
@Override protected void processRequest() throws Exception {
  UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
  FormProcessor fp=new FormProcessor(request);
  int studyId=fp.getInt(ARG_STUDY_ID);
  String uName=fp.getString(ARG_USER_NAME);
  StudyUserRoleBean studyUserRole=udao.findRoleByUserNameAndStudyId(uName,studyId);
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  StudyBean sb=(StudyBean)sdao.findByPK(studyUserRole.getStudyId());
  if (sb != null) {
    studyUserRole.setStudyName(sb.getName());
  }
  if (!studyUserRole.isActive()) {
    String message=respage.getString("String_Node_Str");
    addPageMessage(message);
    forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
  }
 else {
    Map roleMap=new LinkedHashMap();
    for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
      Role role=(Role)it.next();
      roleMap.put(role.getId(),role.getDescription());
    }
    roleMap=new LinkedHashMap();
    ResourceBundle resterm=org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
    StudyBean study=(StudyBean)sdao.findByPK(studyUserRole.getStudyId());
    if (study.getParentStudyId() == 0) {
      for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
        Role role=(Role)it.next();
switch (role.getId()) {
case 2:
          roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
        break;
case 3:
      roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
    break;
case 4:
  roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
case 5:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
case 6:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
default :
}
}
}
 else {
for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
Role role=(Role)it.next();
switch (role.getId()) {
case 4:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
case 5:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
case 6:
roleMap.put(role.getId(),resterm.getString("String_Node_Str").trim());
break;
default :
}
}
}
if (study.getParentStudyId() > 0) {
roleMap.remove(Role.COORDINATOR.getId());
roleMap.remove(Role.STUDYDIRECTOR.getId());
}
if (!fp.isSubmitted()) {
request.setAttribute("String_Node_Str",uName);
request.setAttribute("String_Node_Str",studyUserRole);
request.setAttribute("String_Node_Str",roleMap);
request.setAttribute("String_Node_Str",new Integer(studyUserRole.getRole().getId()));
forwardPage(Page.EDIT_STUDY_USER_ROLE);
}
 else {
Validator v=new Validator(request);
v.addValidation(INPUT_ROLE,Validator.IS_VALID_TERM,TermType.ROLE);
HashMap errors=v.validate();
if (errors.isEmpty()) {
int roleId=fp.getInt(INPUT_ROLE);
Role r=Role.get(roleId);
studyUserRole.setRoleName(r.getName());
studyUserRole.setUpdater(ub);
udao.updateStudyUserRole(studyUserRole,uName);
String message=respage.getString("String_Node_Str");
addPageMessage(message);
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
 else {
String message=respage.getString("String_Node_Str");
addPageMessage(message);
request.setAttribute("String_Node_Str",uName);
request.setAttribute("String_Node_Str",studyUserRole);
request.setAttribute("String_Node_Str",new Integer(fp.getInt(INPUT_ROLE)));
request.setAttribute("String_Node_Str",roleMap);
forwardPage(Page.EDIT_STUDY_USER_ROLE);
}
}
}
}