CLOUDSTACK-7930, CLOUDSTACK-7931: Do not allow to set invalid values for global settings which are of type integer and float

This closes #41
This commit is contained in:
Anshul Gangwar 2014-11-17 15:27:22 +05:30 committed by Rajesh Battala
parent bfe53d1b2b
commit b008d78b57
1 changed files with 15 additions and 0 deletions

View File

@ -725,6 +725,21 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
type = c.getType();
}
String errMsg = null;
try {
if (type.equals(Integer.class)) {
errMsg = "There was error in trying to parse value: " + value + ". Please enter a valid integer value for parameter " + name;
Integer.parseInt(value);
} else if (type.equals(Float.class)) {
errMsg = "There was error in trying to parse value: " + value + ". Please enter a valid float value for parameter " + name;
Float.parseFloat(value);
}
} catch (Exception e) {
// catching generic exception as some throws NullPointerException and some throws NumberFormatExcpeion
s_logger.error(errMsg);
return errMsg;
}
if (value == null) {
if (type.equals(Boolean.class)) {
return "Please enter either 'true' or 'false'.";