1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-29 15:51:17 +00:00

ConfigXml: Make getOrDefault more safe by catching NumberFormatException

This commit is contained in:
Catfriend1 2019-01-27 20:06:08 +01:00
parent e4dae20a3a
commit fb07486404

View file

@ -370,7 +370,11 @@ public class ConfigXml {
}
private Integer getAttributeOrDefault(final Element element, String attribute, Integer defaultValue) {
return element.hasAttribute(attribute) ? Integer.parseInt(element.getAttribute(attribute)) : defaultValue;
try {
return element.hasAttribute(attribute) ? Integer.parseInt(element.getAttribute(attribute)) : defaultValue;
} catch (NumberFormatException e) {
return defaultValue;
}
}
private String getAttributeOrDefault(final Element element, String attribute, String defaultValue) {
@ -378,11 +382,23 @@ public class ConfigXml {
}
private Boolean getContentOrDefault(final Node node, Boolean defaultValue) {
return (node == null) ? defaultValue : Boolean.parseBoolean(node.getTextContent());
return (node == null) ? defaultValue : Boolean.parseBoolean(node.getTextContent());
}
private Integer getContentOrDefault(final Node node, Integer defaultValue) {
return (node == null) ? defaultValue : Integer.parseInt(node.getTextContent());
try {
return (node == null) ? defaultValue : Integer.parseInt(node.getTextContent());
} catch (NumberFormatException e) {
return defaultValue;
}
}
private Float getContentOrDefault(final Node node, Float defaultValue) {
try {
return (node == null) ? defaultValue : Float.parseFloat(node.getTextContent());
} catch (NumberFormatException e) {
return defaultValue;
}
}
private String getContentOrDefault(final Node node, String defaultValue) {