Program: 166213
Project: 166213
Buggy source:
public VXUser updateXUser(VXUser vXUser){
  if (vXUser == null || vXUser.getName() == null || "String_Node_Str".equalsIgnoreCase(vXUser.getName()) || vXUser.getName().trim().isEmpty()) {
    throw restErrorUtil.createRESTException("String_Node_Str" + "String_Node_Str",MessageEnums.INVALID_INPUT_DATA);
  }
  checkAccess(vXUser.getName());
  VXPortalUser oldUserProfile=userMgr.getUserProfileByLoginId(vXUser.getName());
  VXPortalUser vXPortalUser=new VXPortalUser();
  if (oldUserProfile != null && oldUserProfile.getId() != null) {
    vXPortalUser.setId(oldUserProfile.getId());
  }
  vXPortalUser.setFirstName(vXUser.getFirstName());
  if ("String_Node_Str".equalsIgnoreCase(vXPortalUser.getFirstName())) {
    vXPortalUser.setFirstName("String_Node_Str");
  }
  vXPortalUser.setLastName(vXUser.getLastName());
  if ("String_Node_Str".equalsIgnoreCase(vXPortalUser.getLastName())) {
    vXPortalUser.setLastName("String_Node_Str");
  }
  vXPortalUser.setEmailAddress(vXUser.getEmailAddress());
  vXPortalUser.setLoginId(vXUser.getName());
  vXPortalUser.setStatus(vXUser.getStatus());
  vXPortalUser.setUserRoleList(vXUser.getUserRoleList());
  if (vXPortalUser.getFirstName() != null && vXPortalUser.getLastName() != null && !vXPortalUser.getFirstName().trim().isEmpty() && !vXPortalUser.getLastName().trim().isEmpty()) {
    vXPortalUser.setPublicScreenName(vXPortalUser.getFirstName() + "String_Node_Str" + vXPortalUser.getLastName());
  }
 else {
    vXPortalUser.setPublicScreenName(vXUser.getName());
  }
  vXPortalUser.setUserSource(vXUser.getUserSource());
  String hiddenPasswordString=PropertiesUtil.getProperty("String_Node_Str","String_Node_Str");
  String password=vXUser.getPassword();
  if (oldUserProfile != null && password != null && password.equals(hiddenPasswordString)) {
    vXPortalUser.setPassword(oldUserProfile.getPassword());
  }
 else   if (oldUserProfile != null && oldUserProfile.getUserSource() == RangerCommonEnums.USER_EXTERNAL && password != null) {
    vXPortalUser.setPassword(oldUserProfile.getPassword());
    logger.debug("String_Node_Str");
  }
 else   if (password != null) {
    validatePassword(vXUser);
    vXPortalUser.setPassword(password);
  }
  Collection<Long> groupIdList=vXUser.getGroupIdList();
  XXPortalUser xXPortalUser=new XXPortalUser();
  xXPortalUser=userMgr.updateUserWithPass(vXPortalUser);
  Collection<String> roleListUpdatedProfile=new ArrayList<String>();
  if (oldUserProfile != null && oldUserProfile.getId() != null) {
    if (vXUser != null && vXUser.getUserRoleList() != null) {
      Collection<String> roleListOldProfile=oldUserProfile.getUserRoleList();
      Collection<String> roleListNewProfile=vXUser.getUserRoleList();
      if (roleListNewProfile != null && roleListOldProfile != null) {
        for (        String role : roleListNewProfile) {
          if (role != null && !roleListOldProfile.contains(role)) {
            roleListUpdatedProfile.add(role);
          }
        }
      }
    }
  }
  if (roleListUpdatedProfile != null && roleListUpdatedProfile.size() > 0) {
    vXPortalUser.setUserRoleList(roleListUpdatedProfile);
    List<XXUserPermission> xuserPermissionList=daoManager.getXXUserPermission().findByUserPermissionId(vXPortalUser.getId());
    if (xuserPermissionList != null && xuserPermissionList.size() > 0) {
      for (      XXUserPermission xXUserPermission : xuserPermissionList) {
        if (xXUserPermission != null) {
          try {
            xUserPermissionService.deleteResource(xXUserPermission.getId());
          }
 catch (          Exception e) {
            logger.error(e.getMessage());
          }
        }
      }
    }
    assignPermissionToUser(vXPortalUser,true);
  }
  Collection<String> roleList=new ArrayList<String>();
  if (xXPortalUser != null) {
    roleList=userMgr.getRolesForUser(xXPortalUser);
  }
  if (roleList == null || roleList.size() == 0) {
    roleList=new ArrayList<String>();
    roleList.add(RangerConstants.ROLE_USER);
  }
  vXUser=xUserService.updateResource(vXUser);
  vXUser.setUserRoleList(roleList);
  if (oldUserProfile.getUserSource() == RangerCommonEnums.USER_APP) {
    vXUser.setPassword(password);
  }
 else   if (oldUserProfile.getUserSource() == RangerCommonEnums.USER_EXTERNAL) {
    vXUser.setPassword(oldUserProfile.getPassword());
  }
  List<XXTrxLog> trxLogList=xUserService.getTransactionLog(vXUser,oldUserProfile,"String_Node_Str");
  vXUser.setPassword(hiddenPasswordString);
  Long userId=vXUser.getId();
  List<Long> groupUsersToRemove=new ArrayList<Long>();
  if (groupIdList != null) {
    SearchCriteria searchCriteria=new SearchCriteria();
    searchCriteria.addParam("String_Node_Str",userId);
    VXGroupUserList vXGroupUserList=xGroupUserService.searchXGroupUsers(searchCriteria);
    List<VXGroupUser> vXGroupUsers=vXGroupUserList.getList();
    if (vXGroupUsers != null) {
      for (      Long groupId : groupIdList) {
        boolean found=false;
        for (        VXGroupUser vXGroupUser : vXGroupUsers) {
          if (groupId.equals(vXGroupUser.getParentGroupId())) {
            found=true;
            break;
          }
        }
        if (!found) {
          VXGroupUser vXGroupUser=createXGroupUser(userId,groupId);
          trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser,"String_Node_Str"));
        }
      }
      for (      VXGroupUser vXGroupUser : vXGroupUsers) {
        boolean found=false;
        for (        Long groupId : groupIdList) {
          if (groupId.equals(vXGroupUser.getParentGroupId())) {
            trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser,"String_Node_Str"));
            found=true;
            break;
          }
        }
        if (!found) {
          trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser,"String_Node_Str"));
          groupUsersToRemove.add(vXGroupUser.getId());
        }
      }
    }
 else {
      for (      Long groupId : groupIdList) {
        VXGroupUser vXGroupUser=createXGroupUser(userId,groupId);
        trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser,"String_Node_Str"));
      }
    }
    vXUser.setGroupIdList(groupIdList);
  }
 else {
    logger.debug("String_Node_Str" + "String_Node_Str" + userId);
  }
  xaBizUtil.createTrxLog(trxLogList);
  for (  Long groupUserId : groupUsersToRemove) {
    xGroupUserService.deleteResource(groupUserId);
  }
  return vXUser;
}

Fixed version (ground truth):
public VXUser updateXUser(VXUser vXUser){
  if (vXUser == null || vXUser.getName() == null || "String_Node_Str".equalsIgnoreCase(vXUser.getName()) || vXUser.getName().trim().isEmpty()) {
    throw restErrorUtil.createRESTException("String_Node_Str" + "String_Node_Str",MessageEnums.INVALID_INPUT_DATA);
  }
  checkAccess(vXUser.getName());
  VXPortalUser oldUserProfile=userMgr.getUserProfileByLoginId(vXUser.getName());
  VXPortalUser vXPortalUser=new VXPortalUser();
  if (oldUserProfile != null && oldUserProfile.getId() != null) {
    vXPortalUser.setId(oldUserProfile.getId());
  }
  vXPortalUser.setFirstName(vXUser.getFirstName());
  if ("String_Node_Str".equalsIgnoreCase(vXPortalUser.getFirstName())) {
    vXPortalUser.setFirstName("String_Node_Str");
  }
  vXPortalUser.setLastName(vXUser.getLastName());
  if ("String_Node_Str".equalsIgnoreCase(vXPortalUser.getLastName())) {
    vXPortalUser.setLastName("String_Node_Str");
  }
  vXPortalUser.setEmailAddress(vXUser.getEmailAddress());
  vXPortalUser.setLoginId(vXUser.getName());
  vXPortalUser.setStatus(vXUser.getStatus());
  vXPortalUser.setUserRoleList(vXUser.getUserRoleList());
  if (vXPortalUser.getFirstName() != null && vXPortalUser.getLastName() != null && !vXPortalUser.getFirstName().trim().isEmpty() && !vXPortalUser.getLastName().trim().isEmpty()) {
    vXPortalUser.setPublicScreenName(vXPortalUser.getFirstName() + "String_Node_Str" + vXPortalUser.getLastName());
  }
 else {
    vXPortalUser.setPublicScreenName(vXUser.getName());
  }
  vXPortalUser.setUserSource(vXUser.getUserSource());
  String hiddenPasswordString=PropertiesUtil.getProperty("String_Node_Str","String_Node_Str");
  String password=vXUser.getPassword();
  if (oldUserProfile != null && password != null && password.equals(hiddenPasswordString)) {
    vXPortalUser.setPassword(oldUserProfile.getPassword());
  }
 else   if (oldUserProfile != null && oldUserProfile.getUserSource() == RangerCommonEnums.USER_EXTERNAL && password != null) {
    vXPortalUser.setPassword(oldUserProfile.getPassword());
    logger.debug("String_Node_Str");
  }
 else   if (password != null) {
    validatePassword(vXUser);
    vXPortalUser.setPassword(password);
  }
  Collection<Long> groupIdList=vXUser.getGroupIdList();
  XXPortalUser xXPortalUser=new XXPortalUser();
  xXPortalUser=userMgr.updateUserWithPass(vXPortalUser);
  Collection<String> roleListUpdatedProfile=new ArrayList<String>();
  if (oldUserProfile != null && oldUserProfile.getId() != null) {
    if (vXUser != null && vXUser.getUserRoleList() != null) {
      Collection<String> roleListOldProfile=oldUserProfile.getUserRoleList();
      Collection<String> roleListNewProfile=vXUser.getUserRoleList();
      if (roleListNewProfile != null && roleListOldProfile != null) {
        for (        String role : roleListNewProfile) {
          if (role != null && !roleListOldProfile.contains(role)) {
            roleListUpdatedProfile.add(role);
          }
        }
      }
    }
  }
  if (roleListUpdatedProfile != null && roleListUpdatedProfile.size() > 0) {
    vXPortalUser.setUserRoleList(roleListUpdatedProfile);
    List<XXUserPermission> xuserPermissionList=daoManager.getXXUserPermission().findByUserPermissionId(vXPortalUser.getId());
    if (xuserPermissionList != null && xuserPermissionList.size() > 0) {
      for (      XXUserPermission xXUserPermission : xuserPermissionList) {
        if (xXUserPermission != null) {
          try {
            xUserPermissionService.deleteResource(xXUserPermission.getId());
          }
 catch (          Exception e) {
            logger.error(e.getMessage());
          }
        }
      }
    }
    assignPermissionToUser(vXPortalUser,true);
  }
  Collection<String> roleList=new ArrayList<String>();
  if (xXPortalUser != null) {
    roleList=userMgr.getRolesForUser(xXPortalUser);
  }
  if (roleList == null || roleList.size() == 0) {
    roleList=new ArrayList<String>();
    roleList.add(RangerConstants.ROLE_USER);
  }
  vXUser=xUserService.updateResource(vXUser);
  vXUser.setUserRoleList(roleList);
  if (oldUserProfile != null) {
    if (oldUserProfile.getUserSource() == RangerCommonEnums.USER_APP) {
      vXUser.setPassword(password);
    }
 else     if (oldUserProfile.getUserSource() == RangerCommonEnums.USER_EXTERNAL) {
      vXUser.setPassword(oldUserProfile.getPassword());
    }
  }
  List<XXTrxLog> trxLogList=xUserService.getTransactionLog(vXUser,oldUserProfile,"String_Node_Str");
  vXUser.setPassword(hiddenPasswordString);
  Long userId=vXUser.getId();
  List<Long> groupUsersToRemove=new ArrayList<Long>();
  if (groupIdList != null) {
    SearchCriteria searchCriteria=new SearchCriteria();
    searchCriteria.addParam("String_Node_Str",userId);
    VXGroupUserList vXGroupUserList=xGroupUserService.searchXGroupUsers(searchCriteria);
    List<VXGroupUser> vXGroupUsers=vXGroupUserList.getList();
    if (vXGroupUsers != null) {
      for (      Long groupId : groupIdList) {
        boolean found=false;
        for (        VXGroupUser vXGroupUser : vXGroupUsers) {
          if (groupId.equals(vXGroupUser.getParentGroupId())) {
            found=true;
            break;
          }
        }
        if (!found) {
          VXGroupUser vXGroupUser=createXGroupUser(userId,groupId);
          trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser,"String_Node_Str"));
        }
      }
      for (      VXGroupUser vXGroupUser : vXGroupUsers) {
        boolean found=false;
        for (        Long groupId : groupIdList) {
          if (groupId.equals(vXGroupUser.getParentGroupId())) {
            trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser,"String_Node_Str"));
            found=true;
            break;
          }
        }
        if (!found) {
          trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser,"String_Node_Str"));
          groupUsersToRemove.add(vXGroupUser.getId());
        }
      }
    }
 else {
      for (      Long groupId : groupIdList) {
        VXGroupUser vXGroupUser=createXGroupUser(userId,groupId);
        trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser,"String_Node_Str"));
      }
    }
    vXUser.setGroupIdList(groupIdList);
  }
 else {
    logger.debug("String_Node_Str" + "String_Node_Str" + userId);
  }
  xaBizUtil.createTrxLog(trxLogList);
  for (  Long groupUserId : groupUsersToRemove) {
    xGroupUserService.deleteResource(groupUserId);
  }
  return vXUser;
}