diff --git a/client/rest/src/main/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumer.java b/client/rest/src/main/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumer.java index 61e06132212..da7f5c79721 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumer.java +++ b/client/rest/src/main/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumer.java @@ -61,6 +61,9 @@ public class HeapBufferedAsyncResponseConsumer extends AbstractAsyncResponseCons * Creates a new instance of this consumer with the provided buffer limit */ public HeapBufferedAsyncResponseConsumer(int bufferLimit) { + if (bufferLimit <= 0) { + throw new IllegalArgumentException("bufferLimit must be greater than 0"); + } this.bufferLimit = bufferLimit; } diff --git a/client/rest/src/test/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumerTests.java b/client/rest/src/test/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumerTests.java index 1d209cd33b3..d30a9e00b53 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumerTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumerTests.java @@ -79,6 +79,16 @@ public class HeapBufferedAsyncResponseConsumerTests extends RestClientTestCase { } public void testConfiguredBufferLimit() throws Exception { + try { + new HeapBufferedAsyncResponseConsumer(randomIntBetween(Integer.MIN_VALUE, 0)); + } catch(IllegalArgumentException e) { + assertEquals("bufferLimit must be greater than 0", e.getMessage()); + } + try { + new HeapBufferedAsyncResponseConsumer(0); + } catch(IllegalArgumentException e) { + assertEquals("bufferLimit must be greater than 0", e.getMessage()); + } int bufferLimit = randomIntBetween(1, MAX_TEST_BUFFER_SIZE - 100); HeapBufferedAsyncResponseConsumer consumer = new HeapBufferedAsyncResponseConsumer(bufferLimit); bufferLimitTest(consumer, bufferLimit);