Skip to content
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

Check Double NaN and Infinity Values #752

Merged
merged 7 commits into from
Mar 18, 2021
Merged

Check Double NaN and Infinity Values #752

merged 7 commits into from
Mar 18, 2021

Conversation

niallzato
Copy link
Contributor

NaN vales are being added to our JSON payload resulting in the entire payload failing. Check for these vales and now set to zero.

@codecov-io
Copy link

codecov-io commented Mar 16, 2021

Codecov Report

Merging #752 (9fde217) into master (b9a49e0) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #752      +/-   ##
==========================================
+ Coverage   81.36%   81.38%   +0.01%     
==========================================
  Files          34       34              
  Lines        2866     2869       +3     
  Branches      342      344       +2     
==========================================
+ Hits         2332     2335       +3     
  Misses        420      420              
  Partials      114      114              
Impacted Files Coverage Δ
.../main/java/com/segment/analytics/Cartographer.java 93.75% <100.00%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9a49e0...9fde217. Read the comment docs.

Copy link
Contributor

@prayansh prayansh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested a slight change, but overall looks 🔥

@@ -212,6 +212,10 @@ private static void writeValue(Object value, JsonWriter writer) throws IOExcepti
if (value == null) {
writer.nullValue();
} else if (value instanceof Number) {
if (value instanceof Double
&& (Double.isNaN((Double) value) || Double.isInfinite((Double) value))) {
value = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets make the value explicity 0.0, to conform to a double value

@@ -298,6 +298,27 @@ class CartographerTest {
)
}

@Test
@Throws(IOException::class)
fun encodesInfiniteAndNanDoubles() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@niallzato niallzato merged commit 3995eca into master Mar 18, 2021
@prayansh prayansh deleted the niall/nan_check branch March 18, 2021 21:46
This was referenced Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants