Program: 115190
Project: 115190
Buggy source:
@Override public void processRequest() throws Exception {
  UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  FormProcessor fp=new FormProcessor(request);
  int userId=fp.getInt("String_Node_Str");
  if (userId == 0) {
    addPageMessage(respage.getString("String_Node_Str"));
    forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
  }
 else {
    String action=request.getParameter("String_Node_Str");
    UserAccountBean user=(UserAccountBean)udao.findByPK(userId);
    ArrayList studies=(ArrayList)sdao.findAll();
    ArrayList studiesHaveRole=(ArrayList)sdao.findAllByUser(user.getName());
    studies.removeAll(studiesHaveRole);
    HashSet<StudyBean> studiesNotHaveRole=new HashSet<StudyBean>();
    HashSet<StudyBean> sitesNotHaveRole=new HashSet<StudyBean>();
    for (int i=0; i < studies.size(); i++) {
      StudyBean study1=(StudyBean)studies.get(i);
      boolean hasStudy=false;
      for (int j=0; j < studiesHaveRole.size(); j++) {
        StudyBean study2=(StudyBean)studiesHaveRole.get(j);
        if (study2.getId() == study1.getId()) {
          hasStudy=true;
          break;
        }
      }
      if (!hasStudy) {
        if (study1.getParentStudyId() > 0) {
          sitesNotHaveRole.add(study1);
        }
 else {
          studiesNotHaveRole.add(study1);
        }
      }
    }
    Map roleMap=new LinkedHashMap();
    for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
      Role role=(Role)it.next();
      roleMap.put(role.getId(),role.getDescription());
    }
    Boolean changeRoles=request.getParameter("String_Node_Str") == null ? false : Boolean.parseBoolean(request.getParameter("String_Node_Str"));
    int studyId=fp.getInt("String_Node_Str");
    if (changeRoles) {
      StudyBean study=(StudyBean)sdao.findByPK(studyId);
      roleMap=new LinkedHashMap();
      ResourceBundle resterm=org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
      if (study.getParentStudyId() > 0) {
        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");
}
}
}
 else {
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 {
if (currentStudy.getParentStudyId() > 0) {
roleMap.remove(Role.COORDINATOR.getId());
roleMap.remove(Role.STUDYDIRECTOR.getId());
}
}
request.setAttribute("String_Node_Str",roleMap);
request.setAttribute("String_Node_Str",studyId);
if ("String_Node_Str".equalsIgnoreCase(action) || changeRoles) {
ArrayList finalStudiesNotHaveRole=new ArrayList();
Iterator iter_study=studiesNotHaveRole.iterator();
while (iter_study.hasNext()) {
StudyBean s=(StudyBean)iter_study.next();
finalStudiesNotHaveRole.add(s);
Iterator iter_site=sitesNotHaveRole.iterator();
while (iter_site.hasNext()) {
StudyBean site=(StudyBean)iter_site.next();
if (site.getParentStudyId() == s.getId()) {
finalStudiesNotHaveRole.add(site);
}
}
}
request.setAttribute("String_Node_Str",user);
request.setAttribute("String_Node_Str",finalStudiesNotHaveRole);
StudyUserRoleBean uRole=new StudyUserRoleBean();
uRole.setFirstName(user.getFirstName());
uRole.setLastName(user.getLastName());
uRole.setUserName(user.getName());
request.setAttribute("String_Node_Str",uRole);
forwardPage(Page.SET_USER_ROLE);
}
 else {
String userName=fp.getString("String_Node_Str");
studyId=fp.getInt("String_Node_Str");
StudyBean userStudy=(StudyBean)sdao.findByPK(studyId);
int roleId=fp.getInt("String_Node_Str");
StudyUserRoleBean sur=new StudyUserRoleBean();
sur.setName(userName);
sur.setRole(Role.get(roleId));
sur.setStudyId(studyId);
sur.setStudyName(userStudy.getName());
sur.setStatus(Status.AVAILABLE);
sur.setOwner(ub);
sur.setCreatedDate(new Date());
if (studyId > 0) {
udao.createStudyUserRole(user,sur);
addPageMessage(user.getFirstName() + "String_Node_Str" + user.getLastName()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ user.getName()+ "String_Node_Str"+ respage.getString("String_Node_Str")+ "String_Node_Str"+ sur.getRole().getDescription()+ "String_Node_Str"+ respage.getString("String_Node_Str")+ "String_Node_Str"+ userStudy.getName()+ "String_Node_Str");
}
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
}
}

Fixed version (ground truth):
@Override public void processRequest() throws Exception {
  UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  FormProcessor fp=new FormProcessor(request);
  int userId=fp.getInt("String_Node_Str");
  if (userId == 0) {
    addPageMessage(respage.getString("String_Node_Str"));
    forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
  }
 else {
    String action=request.getParameter("String_Node_Str");
    UserAccountBean user=(UserAccountBean)udao.findByPK(userId);
    ArrayList studies=(ArrayList)sdao.findAll();
    ArrayList studiesHaveRole=(ArrayList)sdao.findAllByUser(user.getName());
    studies.removeAll(studiesHaveRole);
    HashSet<StudyBean> studiesNotHaveRole=new HashSet<StudyBean>();
    HashSet<StudyBean> sitesNotHaveRole=new HashSet<StudyBean>();
    for (int i=0; i < studies.size(); i++) {
      StudyBean study1=(StudyBean)studies.get(i);
      boolean hasStudy=false;
      for (int j=0; j < studiesHaveRole.size(); j++) {
        StudyBean study2=(StudyBean)studiesHaveRole.get(j);
        if (study2.getId() == study1.getId()) {
          hasStudy=true;
          break;
        }
      }
      if (!hasStudy) {
        if (study1.getParentStudyId() > 0) {
          sitesNotHaveRole.add(study1);
        }
 else {
          studiesNotHaveRole.add(study1);
        }
      }
    }
    Map roleMap=new LinkedHashMap();
    for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
      Role role=(Role)it.next();
      roleMap.put(role.getId(),role.getDescription());
    }
    Boolean changeRoles=request.getParameter("String_Node_Str") == null ? false : Boolean.parseBoolean(request.getParameter("String_Node_Str"));
    int studyId=fp.getInt("String_Node_Str");
    if (changeRoles) {
      StudyBean study=(StudyBean)sdao.findByPK(studyId);
      roleMap=new LinkedHashMap();
      ResourceBundle resterm=org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
      if (study.getParentStudyId() > 0) {
        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 :
}
}
}
 else {
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 {
if (currentStudy.getParentStudyId() > 0) {
roleMap.remove(Role.COORDINATOR.getId());
roleMap.remove(Role.STUDYDIRECTOR.getId());
}
}
request.setAttribute("String_Node_Str",roleMap);
request.setAttribute("String_Node_Str",studyId);
if ("String_Node_Str".equalsIgnoreCase(action) || changeRoles) {
ArrayList finalStudiesNotHaveRole=new ArrayList();
Iterator iter_study=studiesNotHaveRole.iterator();
while (iter_study.hasNext()) {
StudyBean s=(StudyBean)iter_study.next();
finalStudiesNotHaveRole.add(s);
Iterator iter_site=sitesNotHaveRole.iterator();
while (iter_site.hasNext()) {
StudyBean site=(StudyBean)iter_site.next();
if (site.getParentStudyId() == s.getId()) {
finalStudiesNotHaveRole.add(site);
}
}
}
request.setAttribute("String_Node_Str",user);
request.setAttribute("String_Node_Str",finalStudiesNotHaveRole);
StudyUserRoleBean uRole=new StudyUserRoleBean();
uRole.setFirstName(user.getFirstName());
uRole.setLastName(user.getLastName());
uRole.setUserName(user.getName());
request.setAttribute("String_Node_Str",uRole);
forwardPage(Page.SET_USER_ROLE);
}
 else {
String userName=fp.getString("String_Node_Str");
studyId=fp.getInt("String_Node_Str");
StudyBean userStudy=(StudyBean)sdao.findByPK(studyId);
int roleId=fp.getInt("String_Node_Str");
StudyUserRoleBean sur=new StudyUserRoleBean();
sur.setName(userName);
sur.setRole(Role.get(roleId));
sur.setStudyId(studyId);
sur.setStudyName(userStudy.getName());
sur.setStatus(Status.AVAILABLE);
sur.setOwner(ub);
sur.setCreatedDate(new Date());
if (studyId > 0) {
udao.createStudyUserRole(user,sur);
addPageMessage(user.getFirstName() + "String_Node_Str" + user.getLastName()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ user.getName()+ "String_Node_Str"+ respage.getString("String_Node_Str")+ "String_Node_Str"+ sur.getRole().getDescription()+ "String_Node_Str"+ respage.getString("String_Node_Str")+ "String_Node_Str"+ userStudy.getName()+ "String_Node_Str");
}
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
}
}