Skip to content

Commit 0e9fd67

Browse files
shwstpprweizhouapache
authored andcommitted
avoid chances of npe if both guestos name and displayname are null
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent af7fd5d commit 0e9fd67

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,11 +1988,20 @@ protected String getTrimmedHostNameForWindows(String name) {
19881988
return hostName;
19891989
}
19901990

1991-
protected Pair<String, String> getNextVmHostAndDisplayName(AutoScaleVmGroupVO asGroup, VirtualMachineTemplate template) {
1992-
template.getGuestOSId();
1991+
protected boolean isWindowsOs(VirtualMachineTemplate template) {
19931992
GuestOSVO guestOSVO = guestOSDao.findById(template.getGuestOSId());
1994-
String osName = guestOSVO != null ? StringUtils.firstNonBlank(guestOSVO.getName(), guestOSVO.getDisplayName()) : "";
1995-
boolean isWindows = osName.toLowerCase().contains("windows");
1993+
if (guestOSVO == null) {
1994+
return false;
1995+
}
1996+
String osName = StringUtils.firstNonBlank(guestOSVO.getName(), guestOSVO.getDisplayName());
1997+
if (StringUtils.isBlank(osName)) {
1998+
return false;
1999+
}
2000+
return osName.toLowerCase().contains("windows");
2001+
}
2002+
2003+
protected Pair<String, String> getNextVmHostAndDisplayName(AutoScaleVmGroupVO asGroup, VirtualMachineTemplate template) {
2004+
boolean isWindows = isWindowsOs(template);
19962005
String vmHostNameSuffix = "-" + asGroup.getNextVmSeq() + "-" +
19972006
RandomStringUtils.random(VM_HOSTNAME_RANDOM_SUFFIX_LENGTH, 0, 0, true, false, (char[])null, new SecureRandom()).toLowerCase();
19982007
// Truncate vm group name because max length of vm name is 63

0 commit comments

Comments
 (0)