mirror of
https://github.com/apache/cloudstack
synced 2026-08-30 00:52:15 +00:00
Merge pull request #878 from borisroman/CLOUDSTACK-8890
[4.6][BLOCKER]CLOUDSTACK-8890: Added isEmpty() check to prevent nullPointerException.Check if the list is empty before trying to get the first entry. If the list is empty, in example when dealing with projects, it will user the caller user id. Tests to verify working order: 1. Deploy ACS 2. Create project 3. Create resource in project -> Should succeed! * pr/878: Added isEmpty() check to prevent nullPointerException. Signed-off-by: Wido den Hollander <wido@widodh.nl>
This commit is contained in:
commit
73c7ad9a4a
@ -79,6 +79,7 @@ import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.db.DB;
|
||||
@ -279,7 +280,10 @@ public class LoadBalanceRuleHandler {
|
||||
|
||||
long userId = CallContext.current().getCallingUserId();
|
||||
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
|
||||
if (!userVOs.isEmpty()) {
|
||||
userId = userVOs.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
ServiceOfferingVO elasticLbVmOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.elbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
|
||||
|
||||
@ -97,6 +97,7 @@ import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
@ -772,7 +773,10 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
|
||||
|
||||
long userId = CallContext.current().getCallingUserId();
|
||||
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
|
||||
if (!userVOs.isEmpty()) {
|
||||
userId = userVOs.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
internalLbVm =
|
||||
|
||||
@ -53,6 +53,7 @@ import com.cloud.projects.Project;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.NicProfile;
|
||||
@ -112,7 +113,10 @@ public class ServiceManagerImpl implements ServiceManager {
|
||||
|
||||
long userId = CallContext.current().getCallingUserId();
|
||||
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
|
||||
if (!userVOs.isEmpty()) {
|
||||
userId = userVOs.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
ServiceVirtualMachine svm =
|
||||
|
||||
@ -84,6 +84,7 @@ import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
@ -486,7 +487,10 @@ public class NetworkHelperImpl implements NetworkHelper {
|
||||
|
||||
long userId = CallContext.current().getCallingUserId();
|
||||
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
|
||||
if (!userVOs.isEmpty()) {
|
||||
userId = userVOs.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id,
|
||||
|
||||
@ -3220,7 +3220,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
|
||||
long userId = CallContext.current().getCallingUserId();
|
||||
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
|
||||
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
|
||||
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
|
||||
if (!userVOs.isEmpty()) {
|
||||
userId = userVOs.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
UserVmVO vm = commitUserVm(zone, template, hostName, displayName, owner, diskOfferingId, diskSize, userData, caller, isDisplayVm, keyboard, accountId, userId, offering,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user