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

Guard against null geoBoundingBox #50506

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.search.aggregations.metrics;

import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.geo.GeoBoundingBox;
import org.elasticsearch.common.geo.GeoPoint;
Expand All @@ -30,14 +31,17 @@

import java.io.IOException;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.common.geo.GeoBoundingBox.BOTTOM_RIGHT_FIELD;
import static org.elasticsearch.common.geo.GeoBoundingBox.BOUNDS_FIELD;
import static org.elasticsearch.common.geo.GeoBoundingBox.LAT_FIELD;
import static org.elasticsearch.common.geo.GeoBoundingBox.LON_FIELD;
import static org.elasticsearch.common.geo.GeoBoundingBox.TOP_LEFT_FIELD;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

public class ParsedGeoBounds extends ParsedAggregation implements GeoBounds {

// A top of Double.NEGATIVE_INFINITY yields an empty xContent, so the bounding box is null
@Nullable
private GeoBoundingBox geoBoundingBox;

@Override
Expand All @@ -54,13 +58,15 @@ public XContentBuilder doXContentBody(XContentBuilder builder, Params params) th
}

@Override
@Nullable
public GeoPoint topLeft() {
return geoBoundingBox.topLeft();
return geoBoundingBox != null ? geoBoundingBox.topLeft() : null;
}

@Override
@Nullable
public GeoPoint bottomRight() {
return geoBoundingBox.bottomRight();
return geoBoundingBox != null ? geoBoundingBox.bottomRight() : null;
}

private static final ObjectParser<ParsedGeoBounds, Void> PARSER = new ObjectParser<>(ParsedGeoBounds.class.getSimpleName(), true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.aggregations.metrics.InternalGeoBounds;
import org.elasticsearch.search.aggregations.metrics.ParsedGeoBounds;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.test.InternalAggregationTestCase;

Expand Down