-
Notifications
You must be signed in to change notification settings - Fork 32
fix(number validation): Don't track NaN, Infinity, -Infinity, or > 2^53 #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pull Request Test Coverage Report for Build 804
💛 - Coveralls |
Pull Request Test Coverage Report for Build 861
💛 - Coveralls |
return Math.abs((Long) conditionValue) <= Math.pow(2, 53); | ||
} else if (conditionValue instanceof Float) { | ||
Float value = ((Number) conditionValue).floatValue(); | ||
return !(value.isNaN() || value.isInfinite() || value > Math.pow(2, 53)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both validations look same for double and float, please consolidate into one.
} else if (conditionValue instanceof Double) { | ||
Double value = ((Number) conditionValue).doubleValue(); | ||
return !(value.isNaN() || value.isInfinite()); | ||
return !(value.isNaN() || value.isInfinite() || value > Math.pow(2, 53)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.abs missing or double doesn't take -ve values?
@@ -218,4 +217,19 @@ public LogEvent createConversionEvent(@Nonnull ProjectConfig projectConfig, | |||
|
|||
return attributesList; | |||
} | |||
|
|||
private static boolean isValidNumber(Object conditionValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/optimizely/java-sdk/pull/249/files#diff-922db348b1c4d7acd0c13f647f829eb6R73
we have two methods with same name, same functionality, can't it go into single helper method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add documentation of this method.
* causing an exception to be thrown and passing only the valid attributes. | ||
*/ | ||
@Test | ||
public void createConversionEventIgnoresInvalidAndAcceptsValidValueOfValidTypeAttributes() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add -ve value cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too long method name, please make it bit shorter.
@@ -72,10 +72,15 @@ public static MatchType getMatchType(String matchType, Object conditionValue) { | |||
|
|||
private static boolean isValidNumber(Object conditionValue) { | |||
if (conditionValue instanceof Integer) { | |||
return Math.abs((Integer) conditionValue) <= 1e53; | |||
return Math.abs((Integer) conditionValue) <= Math.pow(2, 53); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add documentation of this method.
# Conflicts: # core-api/src/main/java/com/optimizely/ab/event/internal/EventFactory.java
Hi, sorry for the delayed code review. Could we please revive this PR? In addition to merging
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will have to rebase and adjust the new test.
* causing an exception to be thrown and passing only the valid attributes. | ||
*/ | ||
@Test | ||
public void createConversionEventIgnoresInvalidAcceptValidValOfValidAttr() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you will have to adjust this test to accommodate changes from: #250
The expectation is that there will be no decisions and enrich_decisions
should be set to true
* causing an exception to be thrown and passing only the valid attributes. | ||
*/ | ||
@Test | ||
public void createConversionEventIgnoresNegativeInvalidAndAcceptsValidValueOfValidTypeAttributes() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar feedback as above.
Thanks for the updates! The new code looks good. But I just realized that when we evaluate targeting conditions, we probably ought to call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thanks for updating!
@mnoman09 do you think you could pull in latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the nits.
Please address.
|
||
// Bucket to the first variation for all experiments. However, only a subset of the experiments will actually | ||
// call the bucket function. | ||
for (Experiment experiment : allExperiments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this for loop now right?
assertEquals(impression.getVisitors().get(0).getAttributes().get(0).getKey(), boolAttribute.getKey()); | ||
assertEquals(impression.getVisitors().get(0).getAttributes().get(0).getValue(), validBoolAttribute); | ||
assertEquals(impression.getVisitors().get(0).getAttributes().get(1).getKey(), validFloatAttribute.getKey()); | ||
//In below condition I am checking Value of float with double value because impression gets visitors from json so that converts it into double |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit. Change this to:
In the condition below we are checking Value of float with double value because impression gets visitors from JSON so that converts it into double
attributes, | ||
eventTagMap); | ||
|
||
EventBatch impression = gson.fromJson(conversionEvent.getBody(), EventBatch.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you calling this impression? Shouldn't this be called conversion?
|
||
// Bucket to the first variation for all experiments. However, only a subset of the experiments will actually | ||
// call the bucket function. | ||
for (Experiment experiment : allExperiments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again. This is not needed right.
attributes, | ||
eventTagMap); | ||
|
||
EventBatch impression = gson.fromJson(conversionEvent.getBody(), EventBatch.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should technically be called conversion and not impression right?
# Conflicts: # core-api/src/main/java/com/optimizely/ab/config/audience/match/GTMatch.java # core-api/src/main/java/com/optimizely/ab/config/audience/match/LTMatch.java
Summary
Test plan