Skip to content

Commit 73c7ad9

Browse files
committed
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 <[email protected]>
2 parents a0f8f56 + 80cb3ad commit 73c7ad9

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import com.cloud.storage.dao.VMTemplateDao;
8080
import com.cloud.user.Account;
8181
import com.cloud.user.AccountService;
82+
import com.cloud.user.UserVO;
8283
import com.cloud.user.dao.AccountDao;
8384
import com.cloud.user.dao.UserDao;
8485
import com.cloud.utils.db.DB;
@@ -279,7 +280,10 @@ private DomainRouterVO deployELBVm(Network guestNetwork, final DeployDestination
279280

280281
long userId = CallContext.current().getCallingUserId();
281282
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
282-
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
283+
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
284+
if (!userVOs.isEmpty()) {
285+
userId = userVOs.get(0).getId();
286+
}
283287
}
284288

285289
ServiceOfferingVO elasticLbVmOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.elbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));

plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import com.cloud.user.Account;
9898
import com.cloud.user.AccountManager;
9999
import com.cloud.user.User;
100+
import com.cloud.user.UserVO;
100101
import com.cloud.user.dao.UserDao;
101102
import com.cloud.utils.Pair;
102103
import com.cloud.utils.component.ManagerBase;
@@ -772,7 +773,10 @@ protected DomainRouterVO deployInternalLbVm(final Account owner, final DeployDes
772773

773774
long userId = CallContext.current().getCallingUserId();
774775
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
775-
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
776+
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
777+
if (!userVOs.isEmpty()) {
778+
userId = userVOs.get(0).getId();
779+
}
776780
}
777781

778782
internalLbVm =

plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.cloud.template.VirtualMachineTemplate;
5454
import com.cloud.user.Account;
5555
import com.cloud.user.AccountService;
56+
import com.cloud.user.UserVO;
5657
import com.cloud.user.dao.UserDao;
5758
import com.cloud.utils.exception.CloudRuntimeException;
5859
import com.cloud.vm.NicProfile;
@@ -112,7 +113,10 @@ private ServiceVirtualMachine createServiceVM(DataCenter zone, Account owner, Vi
112113

113114
long userId = CallContext.current().getCallingUserId();
114115
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
115-
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
116+
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
117+
if (!userVOs.isEmpty()) {
118+
userId = userVOs.get(0).getId();
119+
}
116120
}
117121

118122
ServiceVirtualMachine svm =

server/src/com/cloud/network/router/NetworkHelperImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import com.cloud.user.Account;
8585
import com.cloud.user.AccountManager;
8686
import com.cloud.user.User;
87+
import com.cloud.user.UserVO;
8788
import com.cloud.user.dao.UserDao;
8889
import com.cloud.utils.exception.CloudRuntimeException;
8990
import com.cloud.utils.net.NetUtils;
@@ -486,7 +487,10 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy
486487

487488
long userId = CallContext.current().getCallingUserId();
488489
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
489-
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
490+
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
491+
if (!userVOs.isEmpty()) {
492+
userId = userVOs.get(0).getId();
493+
}
490494
}
491495

492496
router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id,

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3220,7 +3220,10 @@ protected UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOf
32203220

32213221
long userId = CallContext.current().getCallingUserId();
32223222
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
3223-
userId = _userDao.listByAccount(owner.getAccountId()).get(0).getId();
3223+
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
3224+
if (!userVOs.isEmpty()) {
3225+
userId = userVOs.get(0).getId();
3226+
}
32243227
}
32253228

32263229
UserVmVO vm = commitUserVm(zone, template, hostName, displayName, owner, diskOfferingId, diskSize, userData, caller, isDisplayVm, keyboard, accountId, userId, offering,

0 commit comments

Comments
 (0)