From 0aa19186ae3302e60c521d90d71563c64d68d024 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Thu, 12 Apr 2018 10:13:40 -0400 Subject: [PATCH] Fix NPE in InternalGeoCentroidTests#testReduceRandom (#29481) In some rare cases all inputs might have zero count and resulting in zero totalCount, and null in centroid causing NPE. Closes #29480 --- .../metrics/geocentroid/InternalGeoCentroidTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java index c797fcb91db..9dc7896638c 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java @@ -68,8 +68,10 @@ public class InternalGeoCentroidTests extends InternalAggregationTestCase 0) { + assertEquals(latSum/totalCount, reduced.centroid().getLat(), 1E-5D); + assertEquals(lonSum/totalCount, reduced.centroid().getLon(), 1E-5D); + } assertEquals(totalCount, reduced.count()); }