Skip to content

Commit 32e3d08

Browse files
committed
Fix NPE while deleting domain
1 parent 0d42842 commit 32e3d08

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

engine/schema/src/main/java/com/cloud/user/AccountDetailsDaoImpl.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.HashMap;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.Optional;
2223

2324
import javax.inject.Inject;
2425

@@ -133,17 +134,19 @@ public String getConfigValue(long id, ConfigKey<?> key) {
133134
// check if we can traverse till ROOT domain to get the value
134135
String enableDomainSettingsForChildDomain = _configDao.getValue("enable.domain.settings.for.child.domain");
135136
if (Boolean.parseBoolean(enableDomainSettingsForChildDomain)) {
136-
AccountVO account = _accountDao.findById(id);
137-
DomainVO domain = _domainDao.findById(account.getDomainId());
138-
while (domain != null) {
139-
DomainDetailVO domainVO = _domainDetailsDao.findDetail(domain.getId(), key.key());
140-
if (domainVO != null) {
141-
value = domainVO.getValue();
142-
break;
143-
} else if (domain.getParent() != null) {
144-
domain = _domainDao.findById(domain.getParent());
145-
} else {
146-
break;
137+
Optional<AccountVO> account = Optional.ofNullable(_accountDao.findById(id));
138+
if (account.isPresent()) {
139+
DomainVO domain = _domainDao.findById(account.get().getDomainId());
140+
while (domain != null) {
141+
DomainDetailVO domainVO = _domainDetailsDao.findDetail(domain.getId(), key.key());
142+
if (domainVO != null) {
143+
value = domainVO.getValue();
144+
break;
145+
} else if (domain.getParent() != null) {
146+
domain = _domainDao.findById(domain.getParent());
147+
} else {
148+
break;
149+
}
147150
}
148151
}
149152
}

0 commit comments

Comments
 (0)