Skip to content

Commit 3cf8d46

Browse files
committed
catch number format exception for parsing integer and double
1 parent 98a5e00 commit 3cf8d46

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
@@ -394,7 +394,13 @@ public void track(@Nonnull String eventName,
394394
LiveVariable.VariableType.DOUBLE
395395
);
396396
if (variableValue != null) {
397-
return Double.parseDouble(variableValue);
397+
try {
398+
return Double.parseDouble(variableValue);
399+
}
400+
catch (NumberFormatException exception) {
401+
logger.error("NumberFormatException while trying to parse \"" + variableValue +
402+
"\" as Double. " + exception);
403+
}
398404
}
399405
return null;
400406
}
@@ -434,7 +440,13 @@ public void track(@Nonnull String eventName,
434440
LiveVariable.VariableType.INTEGER
435441
);
436442
if (variableValue != null) {
437-
return Integer.parseInt(variableValue);
443+
try {
444+
return Integer.parseInt(variableValue);
445+
}
446+
catch (NumberFormatException exception) {
447+
logger.error("NumberFormatException while trying to parse \"" + variableValue +
448+
"\" as Integer. " + exception.toString());
449+
}
438450
}
439451
return null;
440452
}

0 commit comments

Comments
 (0)