Skip to content

Commit c8f4d0c

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 855fd9b commit c8f4d0c

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
@@ -1044,7 +1044,7 @@ private static ZParams toZParams(Aggregate aggregate, Weights weights) {
10441044
@SuppressWarnings("unchecked")
10451045
private static Tuple toTuple(List<?> bytes) {
10461046

1047-
if (bytes.isEmpty()) {
1047+
if (bytes == null || bytes.isEmpty()) {
10481048
return null;
10491049
}
10501050

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
@@ -2280,6 +2280,9 @@ public void zPopMinShouldWorkCorrectly() {
22802280
@EnabledOnCommand("BZPOPMIN")
22812281
public void bzPopMinShouldWorkCorrectly() {
22822282

2283+
assertThat(clusterConnection.bZPopMin(KEY_1_BYTES, 1, TimeUnit.MILLISECONDS))
2284+
.isNull();
2285+
22832286
nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
22842287
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
22852288
nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES);
@@ -2305,6 +2308,9 @@ public void zPopMaxShouldWorkCorrectly() {
23052308
@EnabledOnCommand("BZPOPMAX")
23062309
public void bzPopMaxShouldWorkCorrectly() {
23072310

2311+
assertThat(clusterConnection.bZPopMax(KEY_1_BYTES, 1, TimeUnit.MILLISECONDS))
2312+
.isNull();
2313+
23082314
nativeConnection.zadd(KEY_1_BYTES, 10D, VALUE_1_BYTES);
23092315
nativeConnection.zadd(KEY_1_BYTES, 20D, VALUE_2_BYTES);
23102316
nativeConnection.zadd(KEY_1_BYTES, 30D, VALUE_3_BYTES);

0 commit comments

Comments
 (0)