Skip to content

Commit 9af6082

Browse files
jdeppe-pivotalmp911de
authored andcommitted
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
1 parent 6b00487 commit 9af6082

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ private static ZParams toZParams(Aggregate aggregate, Weights weights) {
12561256
@SuppressWarnings("unchecked")
12571257
private static Tuple toTuple(List<?> bytes) {
12581258

1259-
if (bytes.isEmpty()) {
1259+
if (bytes == null || bytes.isEmpty()) {
12601260
return null;
12611261
}
12621262

src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,9 @@ public void zPopMinShouldWorkCorrectly() {
22772277
@EnabledOnCommand("BZPOPMIN")
22782278
public void bzPopMinShouldWorkCorrectly() {
22792279

2280+
assertThat(clusterConnection.bZPopMin(KEY_1_BYTES, 1, TimeUnit.MILLISECONDS))
2281+
.isNull();
2282+
22802283
nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
22812284
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
22822285
nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES);
@@ -2302,6 +2305,9 @@ public void zPopMaxShouldWorkCorrectly() {
23022305
@EnabledOnCommand("BZPOPMAX")
23032306
public void bzPopMaxShouldWorkCorrectly() {
23042307

2308+
assertThat(clusterConnection.bZPopMax(KEY_1_BYTES, 1, TimeUnit.MILLISECONDS))
2309+
.isNull();
2310+
23052311
nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
23062312
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
23072313
nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES);

0 commit comments

Comments
 (0)