Skip to content

Commit 941223a

Browse files
committed
Replace more internal exceptions with assertions
1 parent 2cea9a7 commit 941223a

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/DownscaleStats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ int getRequiredScaleReductionToReduceBucketCountBy(int desiredCollapsedBucketCou
9595
return i + 1;
9696
}
9797
}
98-
throw new IllegalArgumentException("Cannot reduce the bucket count by " + desiredCollapsedBucketCount);
98+
throw new IllegalStateException("Cannot reduce the bucket count by " + desiredCollapsedBucketCount);
9999
}
100100
}

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialScaleUtils.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,11 @@ private static void checkIndexAndScaleBounds(long index, int scale) {
245245
}
246246

247247
private static void checkScaleBounds(int scale) {
248-
if (scale < MIN_SCALE || scale > MAX_SCALE) {
249-
throw new IllegalArgumentException("scale must be in range [" + MIN_SCALE + ".." + MAX_SCALE + "]");
250-
}
248+
assert scale >= MIN_SCALE && scale <= MAX_SCALE : "scale must be in range [" + MIN_SCALE + ".." + MAX_SCALE + "]";
251249
}
252250

253251
private static void checkIndexBounds(long index) {
254-
if (index < MIN_INDEX || index > MAX_INDEX) {
255-
throw new IllegalArgumentException("index must be in range [" + MIN_INDEX + ".." + MAX_INDEX + "]");
256-
}
252+
assert index >= MIN_INDEX && index <= MAX_INDEX : "index must be in range [" + MIN_INDEX + ".." + MAX_INDEX + "]";
257253
}
258254

259255
/**

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/FixedCapacityExponentialHistogram.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ void reset() {
6060
* @param scale the scale to set for this histogram
6161
*/
6262
void resetBuckets(int scale) {
63-
if (scale > MAX_SCALE || scale < MIN_SCALE) {
64-
throw new IllegalArgumentException("scale must be in range [" + MIN_SCALE + ".." + MAX_SCALE + "]");
65-
}
63+
assert scale >= MIN_SCALE && scale <= MAX_SCALE : "scale must be in range [" + MIN_SCALE + ".." + MAX_SCALE + "]";
6664
negativeBuckets.reset();
6765
positiveBuckets.reset();
6866
bucketScale = scale;
@@ -105,15 +103,9 @@ void setZeroBucket(ZeroBucket zeroBucket) {
105103
* @return {@code true} if the bucket was added, {@code false} if it could not be added due to insufficient capacity
106104
*/
107105
boolean tryAddBucket(long index, long count, boolean isPositive) {
108-
if (index < MIN_INDEX || index > MAX_INDEX) {
109-
throw new IllegalArgumentException("index must be in range [" + MIN_INDEX + ".." + MAX_INDEX + "]");
110-
}
111-
if (isPositive == false && positiveBuckets.numBuckets > 0) {
112-
throw new IllegalArgumentException("Cannot add negative buckets after a positive bucket has been added");
113-
}
114-
if (count <= 0) {
115-
throw new IllegalArgumentException("Cannot add an empty or negative bucket");
116-
}
106+
assert index >= MIN_INDEX && index <= MAX_INDEX : "index must be in range [" + MIN_INDEX + ".." + MAX_INDEX + "]";
107+
assert isPositive || positiveBuckets.numBuckets == 0 : "Cannot add negative buckets after a positive bucket has been added";
108+
assert count > 0 : "Cannot add an empty or negative bucket";
117109
if (isPositive) {
118110
return positiveBuckets.tryAddBucket(index, count);
119111
} else {

0 commit comments

Comments
 (0)