Skip to content

Commit b13c1d0

Browse files
authored
Avoid throw AssertionError in ThrowingDriverContext (#103888) (#103934)
ThrowingDriverContext can bring down Elasticsearch instances as it throws AssertionError. An unreleased bug caused this class to throw AssertionError. This change replaces AssertionError with an assertion and an unsupported exception. I attempted to remove this class, but it requires additional effort to make ExpressionEvaluator.Factory Describable.
1 parent 8b9f084 commit b13c1d0

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/ThrowingDriverContext.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,32 @@
1616
import org.elasticsearch.compute.data.BlockFactory;
1717
import org.elasticsearch.core.Releasable;
1818

19-
public class ThrowingDriverContext extends DriverContext {
20-
public ThrowingDriverContext() {
19+
/**
20+
* A driver context that doesn't support any interaction. Consider it as a place holder where we need a dummy driver context.
21+
*/
22+
final class ThrowingDriverContext extends DriverContext {
23+
ThrowingDriverContext() {
2124
super(new ThrowingBigArrays(), BlockFactory.getNonBreakingInstance());
2225
}
2326

2427
@Override
2528
public BigArrays bigArrays() {
26-
throw new AssertionError("should not reach here");
29+
throw unsupported();
2730
}
2831

2932
@Override
3033
public BlockFactory blockFactory() {
31-
throw new AssertionError("should not reach here");
34+
throw unsupported();
3235
}
3336

3437
@Override
3538
public boolean addReleasable(Releasable releasable) {
36-
throw new AssertionError("should not reach here");
39+
throw unsupported();
40+
}
41+
42+
static UnsupportedOperationException unsupported() {
43+
assert false : "ThrowingDriverContext doesn't support any interaction";
44+
throw new UnsupportedOperationException("ThrowingDriverContext doesn't support any interaction");
3745
}
3846

3947
static class ThrowingBigArrays extends BigArrays {
@@ -44,27 +52,27 @@ static class ThrowingBigArrays extends BigArrays {
4452

4553
@Override
4654
public ByteArray newByteArray(long size, boolean clearOnResize) {
47-
throw new AssertionError("should not reach here");
55+
throw unsupported();
4856
}
4957

5058
@Override
5159
public IntArray newIntArray(long size, boolean clearOnResize) {
52-
throw new AssertionError("should not reach here");
60+
throw unsupported();
5361
}
5462

5563
@Override
5664
public LongArray newLongArray(long size, boolean clearOnResize) {
57-
throw new AssertionError("should not reach here");
65+
throw unsupported();
5866
}
5967

6068
@Override
6169
public FloatArray newFloatArray(long size, boolean clearOnResize) {
62-
throw new AssertionError("should not reach here");
70+
throw unsupported();
6371
}
6472

6573
@Override
6674
public DoubleArray newDoubleArray(long size, boolean clearOnResize) {
67-
throw new AssertionError("should not reach here");
75+
throw unsupported();
6876
}
6977
}
7078
}

0 commit comments

Comments
 (0)