Skip to content

Commit

Permalink
Fix NPE in InternalGeoCentroidTests#testReduceRandom (#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 #29480
  • Loading branch information
imotov committed Apr 12, 2018
1 parent 684f3d8 commit ccec39f
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 ccec39f

Please sign in to comment.