Skip to content

Commit

Permalink
Fix NPE when minBound/maxBound is not set before being called.
Browse files Browse the repository at this point in the history
Signed-off-by: George Apaaboah <george.apaaboah@gmail.com>
  • Loading branch information
GeorgeAp committed Jun 16, 2022
1 parent 8844f05 commit 08956a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit 08956a0

Please sign in to comment.