Skip to content

Commit f8ee363

Browse files
Fix empty value setting
1 parent 703ae5a commit f8ee363

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,37 +1404,39 @@ protected void validateSpecificConfigurationValues(String name, String value, Cl
14041404

14051405
protected Pair<Boolean, String> validateCommaSeparatedKeyValueConfigWithPositiveIntegerValues(String value) {
14061406
try {
1407-
String[] commands = value.split(",");
1408-
for (String command : commands) {
1409-
command = command.trim();
1410-
if (!command.contains("=")) {
1411-
String errorMessage = String.format("Validation failed: Command '%s' does not contain '='.", command);
1412-
return new Pair<>(false, errorMessage);
1413-
}
1407+
if (StringUtils.isNotEmpty(value)) {
1408+
String[] commands = value.split(",");
1409+
for (String command : commands) {
1410+
command = command.trim();
1411+
if (!command.contains("=")) {
1412+
String errorMessage = String.format("Validation failed: Command '%s' does not contain '='.", command);
1413+
return new Pair<>(false, errorMessage);
1414+
}
14141415

1415-
String[] parts = command.split("=");
1416-
if (parts.length != 2) {
1417-
String errorMessage = String.format("Validation failed: Command '%s' is not properly formatted.", command);
1418-
return new Pair<>(false, errorMessage);
1419-
}
1416+
String[] parts = command.split("=");
1417+
if (parts.length != 2) {
1418+
String errorMessage = String.format("Validation failed: Command '%s' is not properly formatted.", command);
1419+
return new Pair<>(false, errorMessage);
1420+
}
14201421

1421-
String commandName = parts[0].trim();
1422-
String valueString = parts[1].trim();
1422+
String commandName = parts[0].trim();
1423+
String valueString = parts[1].trim();
14231424

1424-
if (commandName.isEmpty()) {
1425-
String errorMessage = String.format("Validation failed: Command name is missing in '%s'.", command);
1426-
return new Pair<>(false, errorMessage);
1427-
}
1425+
if (commandName.isEmpty()) {
1426+
String errorMessage = String.format("Validation failed: Command name is missing in '%s'.", command);
1427+
return new Pair<>(false, errorMessage);
1428+
}
14281429

1429-
try {
1430-
int num = Integer.parseInt(valueString);
1431-
if (num <= 0) {
1432-
String errorMessage = String.format("Validation failed: The value for command '%s' is not greater than 0. Invalid value: %d", commandName, num);
1430+
try {
1431+
int num = Integer.parseInt(valueString);
1432+
if (num <= 0) {
1433+
String errorMessage = String.format("Validation failed: The value for command '%s' is not greater than 0. Invalid value: %d", commandName, num);
1434+
return new Pair<>(false, errorMessage);
1435+
}
1436+
} catch (NumberFormatException e) {
1437+
String errorMessage = String.format("Validation failed: The value for command '%s' is not a valid integer. Invalid value: %s", commandName, valueString);
14331438
return new Pair<>(false, errorMessage);
14341439
}
1435-
} catch (NumberFormatException e) {
1436-
String errorMessage = String.format("Validation failed: The value for command '%s' is not a valid integer. Invalid value: %s", commandName, valueString);
1437-
return new Pair<>(false, errorMessage);
14381440
}
14391441
}
14401442

0 commit comments

Comments
 (0)