Skip to content

Commit

Permalink
Better handles number format issues in preferences passed as parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Aug 14, 2021
1 parent 3aebaeb commit b488232
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -305,7 +305,12 @@ public final String get(final String key, final String def) {
*/
public final Integer getInt(final String key, final Integer def) {
String result = System.getProperty(key);
return result == null ? getIntPreference(key, def) : Integer.valueOf(result);
if (result == null) return getIntPreference(key, def);
try {
return Integer.valueOf(result);
} catch (NumberFormatException e) {
return def;
}
}

protected abstract Integer getIntPreference(String key, Integer def);
Expand All @@ -320,7 +325,12 @@ public final Integer getInt(final String key, final Integer def) {
*/
public final Double getDouble(final String key, final Double def) {
String result = System.getProperty(key);
return result == null ? getDoublePreference(key, def) : Double.valueOf(result);
if (result == null) return getDoublePreference(key, def);
try {
return Double.valueOf(result);
} catch (NumberFormatException e) {
return def;
}
}

protected abstract Double getDoublePreference(String key, Double def);
Expand Down

0 comments on commit b488232

Please sign in to comment.