Skip to content

Commit 9494527

Browse files
GeorgeApBukhtawar
authored andcommitted
Fix NPE when minBound/maxBound is not set before being called. (#3605)
Signed-off-by: George Apaaboah <george.apaaboah@gmail.com>
1 parent 688e795 commit 9494527

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/HistogramAggregationBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ public HistogramAggregationBuilder offset(double offset) {
227227

228228
/** Get the current minimum bound that is set on this builder. */
229229
public double minBound() {
230-
return extendedBounds.getMin();
230+
return DoubleBounds.getEffectiveMin(extendedBounds);
231231
}
232232

233233
/** Get the current maximum bound that is set on this builder. */
234234
public double maxBound() {
235-
return extendedBounds.getMax();
235+
return DoubleBounds.getEffectiveMax(extendedBounds);
236236
}
237237

238238
protected DoubleBounds extendedBounds() {

server/src/test/java/org/opensearch/search/aggregations/bucket/HistogramTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ public void testInvalidBounds() {
103103
assertThat(ex.getMessage(), equalTo("max bound [0.4] must be greater than min bound [0.5]"));
104104
}
105105

106+
/**
107+
* Check that minBound/maxBound does not throw {@link NullPointerException} when called before being set.
108+
*/
109+
public void testMinBoundMaxBoundDefaultValues() {
110+
HistogramAggregationBuilder factory = new HistogramAggregationBuilder("foo");
111+
112+
double minValue = factory.minBound();
113+
double maxValue = factory.maxBound();
114+
115+
assertThat(minValue, equalTo(Double.POSITIVE_INFINITY));
116+
assertThat(maxValue, equalTo(Double.NEGATIVE_INFINITY));
117+
}
118+
106119
private List<BucketOrder> randomOrder() {
107120
List<BucketOrder> orders = new ArrayList<>();
108121
switch (randomInt(4)) {

0 commit comments

Comments
 (0)