Program: 166357
Project: 166357
Buggy source:
public VXUser updateXUser(VXUser vXUser){
  if (vXUser == null || vXUser.getName() == null || 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());
  vXPortalUser.setLastName(vXUser.getLastName());
  vXPortalUser.setEmailAddress(vXUser.getEmailAddress());
  vXPortalUser.setLoginId(vXUser.getName());
  vXPortalUser.setStatus(vXUser.getStatus());
  vXPortalUser.setUserRoleList(vXUser.getUserRoleList());
  vXPortalUser.setPublicScreenName(vXUser.getFirstName() + "String_Node_Str" + vXUser.getLastName());
  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());
  }
  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.add(RangerConstants.ROLE_USER);
  }
  vXUser=xUserService.updateResource(vXUser);
  vXUser.setUserRoleList(roleList);
  vXUser.setPassword(password);
  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 || 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());
  vXPortalUser.setLastName(vXUser.getLastName());
  vXPortalUser.setEmailAddress(vXUser.getEmailAddress());
  vXPortalUser.setLoginId(vXUser.getName());
  vXPortalUser.setStatus(vXUser.getStatus());
  vXPortalUser.setUserRoleList(vXUser.getUserRoleList());
  vXPortalUser.setPublicScreenName(vXUser.getFirstName() + "String_Node_Str" + vXUser.getLastName());
  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());
  }
  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);
  vXUser.setPassword(password);
  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;
}