Skip to content

Commit 95e0f96

Browse files
committed
Guard against null geoBoundingBox (elastic#50506)
A geo box with a top value of Double.NEGATIVE_INFINITY will yield an empty xContent which translates to a null `geoBoundingBox`. This commit marks the field as `Nullable` and guards against null when retrieving the `topLeft` and `bottomRight` fields. Fixes elastic#50505 (cherry picked from commit 051718f) Signed-off-by: Andrei Dan <[email protected]>
1 parent 218bd19 commit 95e0f96

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/metrics/ParsedGeoBounds.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.search.aggregations.metrics;
2121

22+
import org.elasticsearch.common.Nullable;
2223
import org.elasticsearch.common.collect.Tuple;
2324
import org.elasticsearch.common.geo.GeoBoundingBox;
2425
import org.elasticsearch.common.geo.GeoPoint;
@@ -30,14 +31,17 @@
3031

3132
import java.io.IOException;
3233

33-
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
3434
import static org.elasticsearch.common.geo.GeoBoundingBox.BOTTOM_RIGHT_FIELD;
3535
import static org.elasticsearch.common.geo.GeoBoundingBox.BOUNDS_FIELD;
3636
import static org.elasticsearch.common.geo.GeoBoundingBox.LAT_FIELD;
3737
import static org.elasticsearch.common.geo.GeoBoundingBox.LON_FIELD;
3838
import static org.elasticsearch.common.geo.GeoBoundingBox.TOP_LEFT_FIELD;
39+
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
3940

4041
public class ParsedGeoBounds extends ParsedAggregation implements GeoBounds {
42+
43+
// A top of Double.NEGATIVE_INFINITY yields an empty xContent, so the bounding box is null
44+
@Nullable
4145
private GeoBoundingBox geoBoundingBox;
4246

4347
@Override
@@ -54,13 +58,15 @@ public XContentBuilder doXContentBody(XContentBuilder builder, Params params) th
5458
}
5559

5660
@Override
61+
@Nullable
5762
public GeoPoint topLeft() {
58-
return geoBoundingBox.topLeft();
63+
return geoBoundingBox != null ? geoBoundingBox.topLeft() : null;
5964
}
6065

6166
@Override
67+
@Nullable
6268
public GeoPoint bottomRight() {
63-
return geoBoundingBox.bottomRight();
69+
return geoBoundingBox != null ? geoBoundingBox.bottomRight() : null;
6470
}
6571

6672
private static final ObjectParser<ParsedGeoBounds, Void> PARSER = new ObjectParser<>(ParsedGeoBounds.class.getSimpleName(), true,

server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalGeoBoundsTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import org.elasticsearch.common.io.stream.Writeable;
2323
import org.elasticsearch.search.aggregations.ParsedAggregation;
24-
import org.elasticsearch.search.aggregations.metrics.InternalGeoBounds;
25-
import org.elasticsearch.search.aggregations.metrics.ParsedGeoBounds;
2624
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
2725
import org.elasticsearch.test.InternalAggregationTestCase;
2826

0 commit comments

Comments
 (0)