diff --git a/src/main/java/com/lambdaworks/redis/cluster/ClusterDistributionChannelWriter.java b/src/main/java/com/lambdaworks/redis/cluster/ClusterDistributionChannelWriter.java index 987981ed3a..7db308c373 100644 --- a/src/main/java/com/lambdaworks/redis/cluster/ClusterDistributionChannelWriter.java +++ b/src/main/java/com/lambdaworks/redis/cluster/ClusterDistributionChannelWriter.java @@ -38,6 +38,8 @@ public ClusterDistributionChannelWriter(RedisChannelWriter defaultWriter) @Override public RedisCommand write(RedisCommand command) { + checkArgument(command != null, "command must not be null"); + RedisCommand commandToSend = command; CommandArgs args = command.getArgs(); RedisChannelWriter channelWriter = null; diff --git a/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java b/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java index bd8b2ca579..fe708bf70a 100644 --- a/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java +++ b/src/main/java/com/lambdaworks/redis/protocol/CommandHandler.java @@ -2,6 +2,8 @@ package com.lambdaworks.redis.protocol; +import static com.google.common.base.Preconditions.checkArgument; + import java.nio.channels.ClosedChannelException; import java.nio.charset.Charset; import java.util.ArrayDeque; @@ -164,6 +166,8 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Interrup @Override public RedisCommand write(RedisCommand command) { + checkArgument(command != null, "command must not be null"); + if (lifecycleState == LifecycleState.CLOSED) { throw new RedisException("Connection is closed"); } @@ -174,10 +178,8 @@ public RedisCommand write(RedisCommand command) { } if ((channel == null || !isConnected()) && !clientOptions.isAutoReconnect()) { - command.setException(new RedisException( - "Connection is in a disconnected state and reconnect is disabled. Commands are not accepted.")); - command.complete(); - return command; + throw new RedisException( + "Connection is in a disconnected state and reconnect is disabled. Commands are not accepted."); } try { diff --git a/src/test/java/com/lambdaworks/redis/ClientTest.java b/src/test/java/com/lambdaworks/redis/ClientTest.java index f5b7f9781a..dd2b079d78 100644 --- a/src/test/java/com/lambdaworks/redis/ClientTest.java +++ b/src/test/java/com/lambdaworks/redis/ClientTest.java @@ -111,9 +111,9 @@ public void disconnectedConnectionWithoutReconnect() throws Exception { connection.quit(); waitUntilDisconnected(connection); try { - connection.get(key).get(); - } catch (Exception e) { - assertThat(e).hasRootCauseInstanceOf(RedisException.class).hasMessageContaining( + connection.get(key); + } catch (RedisException e) { + assertThat(e).hasMessageContaining( "Connection is in a disconnected state and reconnect is disabled"); } finally { connection.close();