Program: 84516
Project: 84516
Buggy source:
/** 
 * @should work for an example
 */
@RequestMapping(value="String_Node_Str",method=RequestMethod.POST) public String handleSubmission(WebRequest request,HttpSession httpSession,ModelMap model,@RequestParam(required=false,value="String_Node_Str") String action,@RequestParam(required=false,value="String_Node_Str") String password,@RequestParam(required=false,value="String_Node_Str") String confirm,@RequestParam(required=false,value="String_Node_Str") String[] roles,@ModelAttribute("String_Node_Str") User user,BindingResult errors){
  UserService us=Context.getUserService();
  MessageSourceService mss=Context.getMessageSourceService();
  if (!Context.isAuthenticated()) {
    errors.reject("String_Node_Str");
  }
 else   if (mss.getMessage("String_Node_Str").equals(action)) {
    Context.becomeUser(user.getSystemId());
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ARGS,user.getPersonName());
    return "String_Node_Str";
  }
 else   if (mss.getMessage("String_Node_Str").equals(action)) {
    try {
      Context.getUserService().purgeUser(user);
      httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
    }
 catch (    Exception ex) {
      httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
      httpSession.setAttribute(WebConstants.OPENMRS_MSG_ARGS,ex.getMessage());
      log.error("String_Node_Str",ex);
    }
    return "String_Node_Str";
  }
 else {
    if (us.hasDuplicateUsername(user))     errors.rejectValue("String_Node_Str","String_Node_Str");
    if (password == null || password.equals("String_Node_Str"))     password="String_Node_Str";
    if (confirm == null || confirm.equals("String_Node_Str"))     confirm="String_Node_Str";
    if (!password.equals(confirm))     errors.reject("String_Node_Str");
    if (password.length() == 0 && isNewUser(user))     errors.reject("String_Node_Str");
    if (password.length() > 0) {
      try {
        OpenmrsUtil.validatePassword(user.getUsername(),password,user.getSystemId());
      }
 catch (      PasswordException e) {
        errors.reject(e.getMessage());
      }
    }
    Set<Role> newRoles=new HashSet<Role>();
    if (roles != null) {
      for (      String r : roles) {
        Role role=null;
        if (user.getRoles() != null)         for (        Role test : user.getRoles())         if (test.getRole().equals(r))         role=test;
        if (role == null) {
          role=us.getRole(r);
          user.addRole(role);
        }
        newRoles.add(role);
      }
    }
    if (user.getRoles() == null)     newRoles.clear();
 else     user.getRoles().retainAll(newRoles);
    Map<String,String> properties=user.getUserProperties();
    if (properties == null)     properties=new HashMap<String,String>();
    Boolean newChangePassword=false;
    String chk=request.getParameter(OpenmrsConstants.USER_PROPERTY_CHANGE_PASSWORD);
    if (chk != null)     newChangePassword=true;
    if (!newChangePassword.booleanValue() && properties.containsKey(OpenmrsConstants.USER_PROPERTY_CHANGE_PASSWORD)) {
      properties.remove(OpenmrsConstants.USER_PROPERTY_CHANGE_PASSWORD);
    }
    if (newChangePassword.booleanValue()) {
      properties.put(OpenmrsConstants.USER_PROPERTY_CHANGE_PASSWORD,newChangePassword.toString());
    }
    String[] keys=request.getParameterValues("String_Node_Str");
    String[] values=request.getParameterValues("String_Node_Str");
    if (keys != null && values != null) {
      for (int x=0; x < keys.length; x++) {
        String key=keys[x];
        String val=values[x];
        properties.put(key,val);
      }
    }
    user.setUserProperties(properties);
    UserValidator uv=new UserValidator();
    uv.validate(user,errors);
    if (errors.hasErrors()) {
      return showForm(user.getUserId(),user,model);
    }
    if (isNewUser(user))     us.saveUser(user,password);
 else {
      us.saveUser(user,null);
      if (!password.equals("String_Node_Str") && Context.hasPrivilege(OpenmrsConstants.PRIV_EDIT_USER_PASSWORDS)) {
        if (log.isDebugEnabled())         log.debug("String_Node_Str" + user + "String_Node_Str"+ Context.getAuthenticatedUser());
        us.changePassword(user,password);
      }
    }
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
  }
  return "String_Node_Str";
}

Fixed version (ground truth):
/** 
 * @should work for an example
 */
@RequestMapping(value="String_Node_Str",method=RequestMethod.POST) public String handleSubmission(WebRequest request,HttpSession httpSession,ModelMap model,@RequestParam(required=false,value="String_Node_Str") String action,@RequestParam(required=false,value="String_Node_Str") String password,@RequestParam(required=false,value="String_Node_Str") String confirm,@RequestParam(required=false,value="String_Node_Str") String[] roles,@RequestParam(required=false,value="String_Node_Str") String createNewPerson,@ModelAttribute("String_Node_Str") User user,BindingResult errors){
  UserService us=Context.getUserService();
  MessageSourceService mss=Context.getMessageSourceService();
  if (!Context.isAuthenticated()) {
    errors.reject("String_Node_Str");
  }
 else   if (mss.getMessage("String_Node_Str").equals(action)) {
    Context.becomeUser(user.getSystemId());
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ARGS,user.getPersonName());
    return "String_Node_Str";
  }
 else   if (mss.getMessage("String_Node_Str").equals(action)) {
    try {
      Context.getUserService().purgeUser(user);
      httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
    }
 catch (    Exception ex) {
      httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
      httpSession.setAttribute(WebConstants.OPENMRS_MSG_ARGS,ex.getMessage());
      log.error("String_Node_Str",ex);
    }
    return "String_Node_Str";
  }
 else {
    if (us.hasDuplicateUsername(user))     errors.rejectValue("String_Node_Str","String_Node_Str");
    if (password == null || password.equals("String_Node_Str"))     password="String_Node_Str";
    if (confirm == null || confirm.equals("String_Node_Str"))     confirm="String_Node_Str";
    if (!password.equals(confirm))     errors.reject("String_Node_Str");
    if (password.length() == 0 && isNewUser(user))     errors.reject("String_Node_Str");
    if (password.length() > 0) {
      try {
        OpenmrsUtil.validatePassword(user.getUsername(),password,user.getSystemId());
      }
 catch (      PasswordException e) {
        errors.reject(e.getMessage());
      }
    }
    Set<Role> newRoles=new HashSet<Role>();
    if (roles != null) {
      for (      String r : roles) {
        Role role=null;
        if (user.getRoles() != null)         for (        Role test : user.getRoles())         if (test.getRole().equals(r))         role=test;
        if (role == null) {
          role=us.getRole(r);
          user.addRole(role);
        }
        newRoles.add(role);
      }
    }
    if (user.getRoles() == null)     newRoles.clear();
 else     user.getRoles().retainAll(newRoles);
    Map<String,String> properties=user.getUserProperties();
    if (properties == null)     properties=new HashMap<String,String>();
    Boolean newChangePassword=false;
    String chk=request.getParameter(OpenmrsConstants.USER_PROPERTY_CHANGE_PASSWORD);
    if (chk != null)     newChangePassword=true;
    if (!newChangePassword.booleanValue() && properties.containsKey(OpenmrsConstants.USER_PROPERTY_CHANGE_PASSWORD)) {
      properties.remove(OpenmrsConstants.USER_PROPERTY_CHANGE_PASSWORD);
    }
    if (newChangePassword.booleanValue()) {
      properties.put(OpenmrsConstants.USER_PROPERTY_CHANGE_PASSWORD,newChangePassword.toString());
    }
    String[] keys=request.getParameterValues("String_Node_Str");
    String[] values=request.getParameterValues("String_Node_Str");
    if (keys != null && values != null) {
      for (int x=0; x < keys.length; x++) {
        String key=keys[x];
        String val=values[x];
        properties.put(key,val);
      }
    }
    user.setUserProperties(properties);
    UserValidator uv=new UserValidator();
    uv.validate(user,errors);
    if (errors.hasErrors()) {
      return showForm(user.getUserId(),createNewPerson,user,model);
    }
    if (isNewUser(user))     us.saveUser(user,password);
 else {
      us.saveUser(user,null);
      if (!password.equals("String_Node_Str") && Context.hasPrivilege(OpenmrsConstants.PRIV_EDIT_USER_PASSWORDS)) {
        if (log.isDebugEnabled())         log.debug("String_Node_Str" + user + "String_Node_Str"+ Context.getAuthenticatedUser());
        us.changePassword(user,password);
      }
    }
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
  }
  return "String_Node_Str";
}