Program: 115188
Project: 115188
Buggy source:
@Override protected void processRequest() throws Exception {
  FormProcessor fp=new FormProcessor(request);
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  ArrayList<StudyBean> all=(ArrayList<StudyBean>)sdao.findAll();
  ArrayList<StudyBean> finalList=new ArrayList<StudyBean>();
  for (  StudyBean sb : all) {
    if (!(sb.getParentStudyId() > 0)) {
      finalList.add(sb);
      finalList.addAll(sdao.findAllByParent(sb.getId()));
    }
  }
  addEntityList("String_Node_Str",finalList,respage.getString("String_Node_Str"),Page.ADMIN_SYSTEM);
  Map roleMap=new LinkedHashMap();
  for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
    Role role=(Role)it.next();
    roleMap.put(role.getId(),role.getDescription());
  }
  request.setAttribute("String_Node_Str",roleMap);
  ArrayList types=UserType.toArrayList();
  types.remove(UserType.INVALID);
  if (!ub.isTechAdmin()) {
    types.remove(UserType.TECHADMIN);
  }
  addEntityList("String_Node_Str",types,respage.getString("String_Node_Str"),Page.ADMIN_SYSTEM);
  Boolean changeRoles=request.getParameter("String_Node_Str") == null ? false : Boolean.parseBoolean(request.getParameter("String_Node_Str"));
  int activeStudy=fp.getInt(INPUT_STUDY);
  if (changeRoles) {
    StudyBean study=(StudyBean)sdao.findByPK(activeStudy);
    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");
}
}
}
request.setAttribute("String_Node_Str",roleMap);
}
request.setAttribute("String_Node_Str",activeStudy);
if (!fp.isSubmitted() || changeRoles) {
String textFields[]={INPUT_USERNAME,INPUT_FIRST_NAME,INPUT_LAST_NAME,INPUT_EMAIL,INPUT_INSTITUTION,INPUT_DISPLAY_PWD};
fp.setCurrentStringValuesAsPreset(textFields);
String ddlbFields[]={INPUT_STUDY,INPUT_ROLE,INPUT_TYPE,INPUT_RUN_WEBSERVICES};
fp.setCurrentIntValuesAsPreset(ddlbFields);
HashMap presetValues=fp.getPresetValues();
String sendPwd=SQLInitServlet.getField("String_Node_Str");
fp.addPresetValue(USER_ACCOUNT_NOTIFICATION,sendPwd);
setPresetValues(presetValues);
forwardPage(Page.CREATE_ACCOUNT);
}
 else {
UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
Validator v=new Validator(request);
v.addValidation(INPUT_USERNAME,Validator.NO_BLANKS);
v.addValidation(INPUT_USERNAME,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,64);
v.addValidation(INPUT_USERNAME,Validator.IS_A_USERNAME);
v.addValidation(INPUT_USERNAME,Validator.USERNAME_UNIQUE,udao);
v.addValidation(INPUT_FIRST_NAME,Validator.NO_BLANKS);
v.addValidation(INPUT_LAST_NAME,Validator.NO_BLANKS);
v.addValidation(INPUT_FIRST_NAME,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,50);
v.addValidation(INPUT_LAST_NAME,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,50);
v.addValidation(INPUT_EMAIL,Validator.NO_BLANKS);
v.addValidation(INPUT_EMAIL,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,120);
v.addValidation(INPUT_EMAIL,Validator.IS_A_EMAIL);
v.addValidation(INPUT_INSTITUTION,Validator.NO_BLANKS);
v.addValidation(INPUT_INSTITUTION,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,255);
v.addValidation(INPUT_STUDY,Validator.ENTITY_EXISTS,sdao);
v.addValidation(INPUT_ROLE,Validator.IS_VALID_TERM,TermType.ROLE);
HashMap errors=v.validate();
if (errors.isEmpty()) {
UserAccountBean createdUserAccountBean=new UserAccountBean();
createdUserAccountBean.setName(fp.getString(INPUT_USERNAME));
createdUserAccountBean.setFirstName(fp.getString(INPUT_FIRST_NAME));
createdUserAccountBean.setLastName(fp.getString(INPUT_LAST_NAME));
createdUserAccountBean.setEmail(fp.getString(INPUT_EMAIL));
createdUserAccountBean.setInstitutionalAffiliation(fp.getString(INPUT_INSTITUTION));
SecurityManager secm=((SecurityManager)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str"));
String password=secm.genPassword();
String passwordHash=secm.encrytPassword(password,getUserDetails());
createdUserAccountBean.setPasswd(passwordHash);
createdUserAccountBean.setPasswdTimestamp(null);
createdUserAccountBean.setLastVisitDate(null);
createdUserAccountBean.setStatus(Status.AVAILABLE);
createdUserAccountBean.setPasswdChallengeQuestion("String_Node_Str");
createdUserAccountBean.setPasswdChallengeAnswer("String_Node_Str");
createdUserAccountBean.setPhone("String_Node_Str");
createdUserAccountBean.setOwner(ub);
createdUserAccountBean.setRunWebservices(fp.getBoolean(INPUT_RUN_WEBSERVICES));
int studyId=fp.getInt(INPUT_STUDY);
Role r=Role.get(fp.getInt(INPUT_ROLE));
createdUserAccountBean=addActiveStudyRole(createdUserAccountBean,studyId,r);
UserType type=UserType.get(fp.getInt("String_Node_Str"));
logger.warn("String_Node_Str" + fp.getInt("String_Node_Str"));
logger.warn("String_Node_Str" + type.getDescription());
createdUserAccountBean.addUserType(type);
createdUserAccountBean=(UserAccountBean)udao.create(createdUserAccountBean);
AuthoritiesDao authoritiesDao=(AuthoritiesDao)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str");
authoritiesDao.saveOrUpdate(new AuthoritiesBean(createdUserAccountBean.getName()));
String displayPwd=fp.getString(INPUT_DISPLAY_PWD);
if (createdUserAccountBean.isActive()) {
addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + createdUserAccountBean.getName()+ "String_Node_Str"+ respage.getString("String_Node_Str"));
if ("String_Node_Str".equalsIgnoreCase(displayPwd)) {
try {
sendNewAccountEmail(createdUserAccountBean,password);
}
 catch (Exception e) {
addPageMessage(respage.getString("String_Node_Str"));
}
}
 else {
addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + password+ "String_Node_Str"+ respage.getString("String_Node_Str"));
}
}
 else {
addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + createdUserAccountBean.getName()+ "String_Node_Str"+ respage.getString("String_Node_Str"));
}
if (createdUserAccountBean.isActive()) {
request.setAttribute(ViewUserAccountServlet.ARG_USER_ID,new Integer(createdUserAccountBean.getId()).toString());
forwardPage(Page.VIEW_USER_ACCOUNT_SERVLET);
}
 else {
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
}
 else {
String textFields[]={INPUT_USERNAME,INPUT_FIRST_NAME,INPUT_LAST_NAME,INPUT_EMAIL,INPUT_INSTITUTION,INPUT_DISPLAY_PWD};
fp.setCurrentStringValuesAsPreset(textFields);
String ddlbFields[]={INPUT_STUDY,INPUT_ROLE,INPUT_TYPE,INPUT_RUN_WEBSERVICES};
fp.setCurrentIntValuesAsPreset(ddlbFields);
HashMap presetValues=fp.getPresetValues();
setPresetValues(presetValues);
setInputMessages(errors);
addPageMessage(respage.getString("String_Node_Str") + respage.getString("String_Node_Str"));
forwardPage(Page.CREATE_ACCOUNT);
}
}
}

Fixed version (ground truth):
@Override protected void processRequest() throws Exception {
  FormProcessor fp=new FormProcessor(request);
  StudyDAO sdao=new StudyDAO(sm.getDataSource());
  ArrayList<StudyBean> all=(ArrayList<StudyBean>)sdao.findAll();
  ArrayList<StudyBean> finalList=new ArrayList<StudyBean>();
  for (  StudyBean sb : all) {
    if (!(sb.getParentStudyId() > 0)) {
      finalList.add(sb);
      finalList.addAll(sdao.findAllByParent(sb.getId()));
    }
  }
  addEntityList("String_Node_Str",finalList,respage.getString("String_Node_Str"),Page.ADMIN_SYSTEM);
  Map roleMap=new LinkedHashMap();
  for (Iterator it=getRoles().iterator(); it.hasNext(); ) {
    Role role=(Role)it.next();
    roleMap.put(role.getId(),role.getDescription());
  }
  request.setAttribute("String_Node_Str",roleMap);
  ArrayList types=UserType.toArrayList();
  types.remove(UserType.INVALID);
  if (!ub.isTechAdmin()) {
    types.remove(UserType.TECHADMIN);
  }
  addEntityList("String_Node_Str",types,respage.getString("String_Node_Str"),Page.ADMIN_SYSTEM);
  Boolean changeRoles=request.getParameter("String_Node_Str") == null ? false : Boolean.parseBoolean(request.getParameter("String_Node_Str"));
  int activeStudy=fp.getInt(INPUT_STUDY);
  if (changeRoles) {
    StudyBean study=(StudyBean)sdao.findByPK(activeStudy);
    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 :
}
}
}
request.setAttribute("String_Node_Str",roleMap);
}
request.setAttribute("String_Node_Str",activeStudy);
if (!fp.isSubmitted() || changeRoles) {
String textFields[]={INPUT_USERNAME,INPUT_FIRST_NAME,INPUT_LAST_NAME,INPUT_EMAIL,INPUT_INSTITUTION,INPUT_DISPLAY_PWD};
fp.setCurrentStringValuesAsPreset(textFields);
String ddlbFields[]={INPUT_STUDY,INPUT_ROLE,INPUT_TYPE,INPUT_RUN_WEBSERVICES};
fp.setCurrentIntValuesAsPreset(ddlbFields);
HashMap presetValues=fp.getPresetValues();
String sendPwd=SQLInitServlet.getField("String_Node_Str");
fp.addPresetValue(USER_ACCOUNT_NOTIFICATION,sendPwd);
setPresetValues(presetValues);
forwardPage(Page.CREATE_ACCOUNT);
}
 else {
UserAccountDAO udao=new UserAccountDAO(sm.getDataSource());
Validator v=new Validator(request);
v.addValidation(INPUT_USERNAME,Validator.NO_BLANKS);
v.addValidation(INPUT_USERNAME,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,64);
v.addValidation(INPUT_USERNAME,Validator.IS_A_USERNAME);
v.addValidation(INPUT_USERNAME,Validator.USERNAME_UNIQUE,udao);
v.addValidation(INPUT_FIRST_NAME,Validator.NO_BLANKS);
v.addValidation(INPUT_LAST_NAME,Validator.NO_BLANKS);
v.addValidation(INPUT_FIRST_NAME,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,50);
v.addValidation(INPUT_LAST_NAME,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,50);
v.addValidation(INPUT_EMAIL,Validator.NO_BLANKS);
v.addValidation(INPUT_EMAIL,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,120);
v.addValidation(INPUT_EMAIL,Validator.IS_A_EMAIL);
v.addValidation(INPUT_INSTITUTION,Validator.NO_BLANKS);
v.addValidation(INPUT_INSTITUTION,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,255);
v.addValidation(INPUT_STUDY,Validator.ENTITY_EXISTS,sdao);
v.addValidation(INPUT_ROLE,Validator.IS_VALID_TERM,TermType.ROLE);
HashMap errors=v.validate();
if (errors.isEmpty()) {
UserAccountBean createdUserAccountBean=new UserAccountBean();
createdUserAccountBean.setName(fp.getString(INPUT_USERNAME));
createdUserAccountBean.setFirstName(fp.getString(INPUT_FIRST_NAME));
createdUserAccountBean.setLastName(fp.getString(INPUT_LAST_NAME));
createdUserAccountBean.setEmail(fp.getString(INPUT_EMAIL));
createdUserAccountBean.setInstitutionalAffiliation(fp.getString(INPUT_INSTITUTION));
SecurityManager secm=((SecurityManager)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str"));
String password=secm.genPassword();
String passwordHash=secm.encrytPassword(password,getUserDetails());
createdUserAccountBean.setPasswd(passwordHash);
createdUserAccountBean.setPasswdTimestamp(null);
createdUserAccountBean.setLastVisitDate(null);
createdUserAccountBean.setStatus(Status.AVAILABLE);
createdUserAccountBean.setPasswdChallengeQuestion("String_Node_Str");
createdUserAccountBean.setPasswdChallengeAnswer("String_Node_Str");
createdUserAccountBean.setPhone("String_Node_Str");
createdUserAccountBean.setOwner(ub);
createdUserAccountBean.setRunWebservices(fp.getBoolean(INPUT_RUN_WEBSERVICES));
int studyId=fp.getInt(INPUT_STUDY);
Role r=Role.get(fp.getInt(INPUT_ROLE));
createdUserAccountBean=addActiveStudyRole(createdUserAccountBean,studyId,r);
UserType type=UserType.get(fp.getInt("String_Node_Str"));
logger.warn("String_Node_Str" + fp.getInt("String_Node_Str"));
logger.warn("String_Node_Str" + type.getDescription());
createdUserAccountBean.addUserType(type);
createdUserAccountBean=(UserAccountBean)udao.create(createdUserAccountBean);
AuthoritiesDao authoritiesDao=(AuthoritiesDao)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str");
authoritiesDao.saveOrUpdate(new AuthoritiesBean(createdUserAccountBean.getName()));
String displayPwd=fp.getString(INPUT_DISPLAY_PWD);
if (createdUserAccountBean.isActive()) {
addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + createdUserAccountBean.getName()+ "String_Node_Str"+ respage.getString("String_Node_Str"));
if ("String_Node_Str".equalsIgnoreCase(displayPwd)) {
try {
sendNewAccountEmail(createdUserAccountBean,password);
}
 catch (Exception e) {
addPageMessage(respage.getString("String_Node_Str"));
}
}
 else {
addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + password+ "String_Node_Str"+ respage.getString("String_Node_Str"));
}
}
 else {
addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + createdUserAccountBean.getName()+ "String_Node_Str"+ respage.getString("String_Node_Str"));
}
if (createdUserAccountBean.isActive()) {
request.setAttribute(ViewUserAccountServlet.ARG_USER_ID,new Integer(createdUserAccountBean.getId()).toString());
forwardPage(Page.VIEW_USER_ACCOUNT_SERVLET);
}
 else {
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
}
 else {
String textFields[]={INPUT_USERNAME,INPUT_FIRST_NAME,INPUT_LAST_NAME,INPUT_EMAIL,INPUT_INSTITUTION,INPUT_DISPLAY_PWD};
fp.setCurrentStringValuesAsPreset(textFields);
String ddlbFields[]={INPUT_STUDY,INPUT_ROLE,INPUT_TYPE,INPUT_RUN_WEBSERVICES};
fp.setCurrentIntValuesAsPreset(ddlbFields);
HashMap presetValues=fp.getPresetValues();
setPresetValues(presetValues);
setInputMessages(errors);
addPageMessage(respage.getString("String_Node_Str") + respage.getString("String_Node_Str"));
forwardPage(Page.CREATE_ACCOUNT);
}
}
}