Skip to content

Commit 2353651

Browse files
committed
catch number format exception for parsing integer and double
1 parent 177bf24 commit 2353651

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

core-api/src/main/java/com/optimizely/ab/Optimizely.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,13 @@ public void track(@Nonnull String eventName,
431431
LiveVariable.VariableType.DOUBLE
432432
);
433433
if (variableValue != null) {
434-
return Double.parseDouble(variableValue);
434+
try {
435+
return Double.parseDouble(variableValue);
436+
}
437+
catch (NumberFormatException exception) {
438+
logger.error("NumberFormatException while trying to parse \"" + variableValue +
439+
"\" as Double. " + exception);
440+
}
435441
}
436442
return null;
437443
}
@@ -471,7 +477,13 @@ public void track(@Nonnull String eventName,
471477
LiveVariable.VariableType.INTEGER
472478
);
473479
if (variableValue != null) {
474-
return Integer.parseInt(variableValue);
480+
try {
481+
return Integer.parseInt(variableValue);
482+
}
483+
catch (NumberFormatException exception) {
484+
logger.error("NumberFormatException while trying to parse \"" + variableValue +
485+
"\" as Integer. " + exception.toString());
486+
}
475487
}
476488
return null;
477489
}

0 commit comments

Comments
 (0)