diff --git a/src/main/java/io/lettuce/core/dynamic/SimpleBatcher.java b/src/main/java/io/lettuce/core/dynamic/SimpleBatcher.java index 3f2edf951b..d0af5950c7 100644 --- a/src/main/java/io/lettuce/core/dynamic/SimpleBatcher.java +++ b/src/main/java/io/lettuce/core/dynamic/SimpleBatcher.java @@ -148,12 +148,12 @@ private List> prepareForceFlush() { List> batch = new ArrayList<>(Math.max(batchSize, 10)); - do { + while (!queue.isEmpty()) { + RedisCommand poll = queue.poll(); - assert poll != null; batch.add(poll); - } while (!queue.isEmpty()); + } return batch; } @@ -166,7 +166,6 @@ private List> prepareDefaultFlush(int consu RedisCommand poll = queue.poll(); - assert poll != null; batch.add(poll); } diff --git a/src/test/java/io/lettuce/core/dynamic/RedisCommandsBatchingIntegrationTests.java b/src/test/java/io/lettuce/core/dynamic/RedisCommandsBatchingIntegrationTests.java index ea9e60c299..17a9ba1050 100644 --- a/src/test/java/io/lettuce/core/dynamic/RedisCommandsBatchingIntegrationTests.java +++ b/src/test/java/io/lettuce/core/dynamic/RedisCommandsBatchingIntegrationTests.java @@ -99,6 +99,16 @@ void selectiveBatchingShouldHandleErrors() { } } + @Test + void shouldNotCrashWhenFlushCalledWithEmptyQueue() { + + RedisCommandFactory factory = new RedisCommandFactory(redis.getStatefulConnection()); + + SelectiveBatchingWithSize api = factory.getCommands(SelectiveBatchingWithSize.class); + + api.flush(); + } + @Test void shouldExecuteBatchingSynchronously() { @@ -215,4 +225,11 @@ static interface SelectiveBatching extends Commands, BatchExecutor { } + @BatchSize(5) + interface SelectiveBatchingWithSize extends Commands, BatchExecutor { + + void set(String key, String value); + + } + }