Skip to content

Commit 25676aa

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
bug 14017: 1) Don't allow NULL value for Boolean type of config 2) Added a null check when compare config values
status 14017: resolved fixed
1 parent 541b18a commit 25676aa

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,6 @@ public boolean stop() {
322322
@Override
323323
@DB
324324
public void updateConfiguration(long userId, String name, String category, String value) {
325-
if (value != null && (value.trim().isEmpty() || value.equals("null"))) {
326-
value = null;
327-
}
328325

329326
String validationMsg = validateConfigurationValue(name, value);
330327

@@ -448,29 +445,39 @@ public Configuration updateConfiguration(UpdateCfgCmd cmd) {
448445
if (value == null) {
449446
return _configDao.findByName(name);
450447
}
448+
449+
if (value.trim().isEmpty() || value.equals("null")) {
450+
value = null;
451+
}
451452

452453
updateConfiguration(userId, name, config.getCategory(), value);
453-
if (_configDao.getValue(name).equalsIgnoreCase(value)) {
454+
String updatedValue = _configDao.getValue(name);
455+
if ((value == null && updatedValue == null) || updatedValue.equalsIgnoreCase(value)) {
454456
return _configDao.findByName(name);
457+
455458
} else {
456459
throw new CloudRuntimeException("Unable to update configuration parameter " + name);
457460
}
458461
}
459462

460463
private String validateConfigurationValue(String name, String value) {
461-
if (value == null) {
462-
return null;
463-
}
464-
464+
465465
Config c = Config.getConfig(name);
466-
value = value.trim();
467-
468466
if (c == null) {
469467
s_logger.error("Missing configuration variable " + name + " in configuration table");
470468
return "Invalid configuration variable.";
471469
}
472470

473471
Class<?> type = c.getType();
472+
473+
if (value == null) {
474+
if (type.equals(Boolean.class)) {
475+
return "Please enter either 'true' or 'false'.";
476+
}
477+
return null;
478+
}
479+
value = value.trim();
480+
474481
if (type.equals(Boolean.class)) {
475482
if (!(value.equals("true") || value.equals("false"))) {
476483
s_logger.error("Configuration variable " + name + " is expecting true or false in stead of " + value);

0 commit comments

Comments
 (0)