Fix potential NullPointerException when using Jedis Cluster BZPOP*.

For the Jedis-based implementations of bzpopmin and bzpopmax, a NPE is
  thrown if the provided timeout elapses and the server responds with a
  null array.

Closes #2324
This commit is contained in:
Jens Deppe
2022-05-13 12:22:55 -07:00
committed by Mark Paluch
parent 92d62f18cc
commit 1923978f88
2 changed files with 7 additions and 1 deletions

View File

@@ -1256,7 +1256,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@SuppressWarnings("unchecked")
private static Tuple toTuple(List<?> bytes) {
if (bytes.isEmpty()) {
if (bytes == null || bytes.isEmpty()) {
return null;
}

View File

@@ -2155,6 +2155,9 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@EnabledOnCommand("BZPOPMIN")
public void bzPopMinShouldWorkCorrectly() {
assertThat(clusterConnection.bZPopMin(KEY_1_BYTES, 1, TimeUnit.MILLISECONDS))
.isNull();
nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES);
@@ -2180,6 +2183,9 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@EnabledOnCommand("BZPOPMAX")
public void bzPopMaxShouldWorkCorrectly() {
assertThat(clusterConnection.bZPopMax(KEY_1_BYTES, 1, TimeUnit.MILLISECONDS))
.isNull();
nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES);