Skip to content

Commit 7f8f927

Browse files
Fix empty value setting
1 parent 1a76b72 commit 7f8f927

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
@@ -1385,37 +1385,39 @@ protected void validateSpecificConfigurationValues(String name, String value, Cl
13851385

13861386
protected Pair<Boolean, String> validateCommaSeparatedKeyValueConfigWithPositiveIntegerValues(String value) {
13871387
try {
1388-
String[] commands = value.split(",");
1389-
for (String command : commands) {
1390-
command = command.trim();
1391-
if (!command.contains("=")) {
1392-
String errorMessage = String.format("Validation failed: Command '%s' does not contain '='.", command);
1393-
return new Pair<>(false, errorMessage);
1394-
}
1388+
if (StringUtils.isNotEmpty(value)) {
1389+
String[] commands = value.split(",");
1390+
for (String command : commands) {
1391+
command = command.trim();
1392+
if (!command.contains("=")) {
1393+
String errorMessage = String.format("Validation failed: Command '%s' does not contain '='.", command);
1394+
return new Pair<>(false, errorMessage);
1395+
}
13951396

1396-
String[] parts = command.split("=");
1397-
if (parts.length != 2) {
1398-
String errorMessage = String.format("Validation failed: Command '%s' is not properly formatted.", command);
1399-
return new Pair<>(false, errorMessage);
1400-
}
1397+
String[] parts = command.split("=");
1398+
if (parts.length != 2) {
1399+
String errorMessage = String.format("Validation failed: Command '%s' is not properly formatted.", command);
1400+
return new Pair<>(false, errorMessage);
1401+
}
14011402

1402-
String commandName = parts[0].trim();
1403-
String valueString = parts[1].trim();
1403+
String commandName = parts[0].trim();
1404+
String valueString = parts[1].trim();
14041405

1405-
if (commandName.isEmpty()) {
1406-
String errorMessage = String.format("Validation failed: Command name is missing in '%s'.", command);
1407-
return new Pair<>(false, errorMessage);
1408-
}
1406+
if (commandName.isEmpty()) {
1407+
String errorMessage = String.format("Validation failed: Command name is missing in '%s'.", command);
1408+
return new Pair<>(false, errorMessage);
1409+
}
14091410

1410-
try {
1411-
int num = Integer.parseInt(valueString);
1412-
if (num <= 0) {
1413-
String errorMessage = String.format("Validation failed: The value for command '%s' is not greater than 0. Invalid value: %d", commandName, num);
1411+
try {
1412+
int num = Integer.parseInt(valueString);
1413+
if (num <= 0) {
1414+
String errorMessage = String.format("Validation failed: The value for command '%s' is not greater than 0. Invalid value: %d", commandName, num);
1415+
return new Pair<>(false, errorMessage);
1416+
}
1417+
} catch (NumberFormatException e) {
1418+
String errorMessage = String.format("Validation failed: The value for command '%s' is not a valid integer. Invalid value: %s", commandName, valueString);
14141419
return new Pair<>(false, errorMessage);
14151420
}
1416-
} catch (NumberFormatException e) {
1417-
String errorMessage = String.format("Validation failed: The value for command '%s' is not a valid integer. Invalid value: %s", commandName, valueString);
1418-
return new Pair<>(false, errorMessage);
14191421
}
14201422
}
14211423

0 commit comments

Comments
 (0)