Skip to content

Commit

Permalink
Fix NPE in InternalGeoCentroidTests#testReduceRandom (elastic#29481)
Browse files Browse the repository at this point in the history
In some rare cases all inputs might have zero count and resulting in
zero totalCount, and null in centroid causing NPE.

Closes elastic#29480
  • Loading branch information
imotov authored Apr 12, 2018
1 parent e0ec857 commit 0aa1918
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ protected void assertReduced(InternalGeoCentroid reduced, List<InternalGeoCentro
}
totalCount += input.count();
}
assertEquals(latSum/totalCount, reduced.centroid().getLat(), 1E-5D);
assertEquals(lonSum/totalCount, reduced.centroid().getLon(), 1E-5D);
if (totalCount > 0) {
assertEquals(latSum/totalCount, reduced.centroid().getLat(), 1E-5D);
assertEquals(lonSum/totalCount, reduced.centroid().getLon(), 1E-5D);
}
assertEquals(totalCount, reduced.count());
}

Expand Down

0 comments on commit 0aa1918

Please sign in to comment.