1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-01 16:51:16 +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) {
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) {
@ -382,7 +386,19 @@ public class ConfigXml {
}
private Integer getContentOrDefault(final Node node, Integer defaultValue) {
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) {