Skip to content

Commit 6a3cfb8

Browse files
committed
Making the code more resilient: if the configuration is messed up (empty string or spaces) or simply doesn’t exist, return the default value (and log the error)
1 parent c278846 commit 6a3cfb8

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/main/java/com/netflix/simianarmy/basic/BasicConfiguration.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@
1717
*/
1818
package com.netflix.simianarmy.basic;
1919

20-
import java.util.Properties;
21-
2220
import com.netflix.simianarmy.MonkeyConfiguration;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
import java.util.Properties;
2324

2425
/**
2526
* The Class BasicConfiguration.
2627
*/
2728
public class BasicConfiguration implements MonkeyConfiguration {
2829

30+
/** The Constant LOGGER. */
31+
private static final Logger LOGGER = LoggerFactory.getLogger(BasicConfiguration.class);
32+
2933
/** The properties. */
3034
private Properties props;
3135

@@ -59,7 +63,15 @@ public boolean getBoolOrElse(String property, boolean dflt) {
5963
@Override
6064
public double getNumOrElse(String property, double dflt) {
6165
String val = props.getProperty(property);
62-
return val == null ? dflt : Double.parseDouble(val);
66+
double result = dflt;
67+
if (val != null && !val.isEmpty()) {
68+
try {
69+
result = Double.parseDouble(val);
70+
} catch (NumberFormatException e) {
71+
LOGGER.error("failed to parse property: " + property + "; returning default value: " + dflt, e);
72+
}
73+
}
74+
return result;
6375
}
6476

6577
/** {@inheritDoc} */

0 commit comments

Comments
 (0)