-
Notifications
You must be signed in to change notification settings - Fork 1.2k
CLOUDSTACK-7930, CLOUDSTACK-7931: Do not allow to set invalid values for global settings which are of type integer and float #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -725,6 +725,21 @@ private String validateConfigurationValue(String name, String value, String scop | |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you catch specific expected exceptions NPE and NFE? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What value will be added by catching specific exceptions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. catching top level exception and swallowing the stacktrace makes it really difficult during debugging. |
||
// 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'."; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we allow values like "3,400.5" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Because they will fail later in parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that it will fail during parsing. But, we can string replace "," with ""