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

[Backport 2.x] Fix NPE when minBound/maxBound is not set before being called. #3610

Merged
merged 1 commit into from
Jun 16, 2022
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 @@ -227,12 +227,12 @@ public HistogramAggregationBuilder offset(double offset) {

/** Get the current minimum bound that is set on this builder. */
public double minBound() {
return extendedBounds.getMin();
return DoubleBounds.getEffectiveMin(extendedBounds);
}

/** Get the current maximum bound that is set on this builder. */
public double maxBound() {
return extendedBounds.getMax();
return DoubleBounds.getEffectiveMax(extendedBounds);
}

protected DoubleBounds extendedBounds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ public void testInvalidBounds() {
assertThat(ex.getMessage(), equalTo("max bound [0.4] must be greater than min bound [0.5]"));
}

/**
* Check that minBound/maxBound does not throw {@link NullPointerException} when called before being set.
*/
public void testMinBoundMaxBoundDefaultValues() {
HistogramAggregationBuilder factory = new HistogramAggregationBuilder("foo");

double minValue = factory.minBound();
double maxValue = factory.maxBound();

assertThat(minValue, equalTo(Double.POSITIVE_INFINITY));
assertThat(maxValue, equalTo(Double.NEGATIVE_INFINITY));
}

private List<BucketOrder> randomOrder() {
List<BucketOrder> orders = new ArrayList<>();
switch (randomInt(4)) {
Expand Down