Skip to content

Commit ceb7c8a

Browse files
retaThomas Darimont
authored and
Thomas Darimont
committed
DATAREDIS-289 - Avoid NPE in DefaultValueOperations#append() in case of pipelining or/and multi/exec calls.
We now return null if DefaultValueOperations#append() was applied to a non-existing list and thus returned null. Previously a NPE was thrown in case of pipelining or/and multi/exec calls. Original pull request: #48.
1 parent 2806567 commit ceb7c8a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public Integer append(K key, String value) {
8383
return execute(new RedisCallback<Integer>() {
8484

8585
public Integer doInRedis(RedisConnection connection) {
86-
return connection.append(rawKey, rawString).intValue();
86+
final Long result = connection.append(rawKey, rawString);
87+
return ( result != null ) ? result.intValue() : null;
8788
}
8889
}, true);
8990
}

src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public List<Object> execute(RedisOperations operations) throws DataAccessExcepti
221221
operations.multi();
222222
operations.opsForValue().set("foo", "5");
223223
operations.opsForValue().get("foo");
224+
operations.opsForValue().append("foo1", "5");
224225
operations.opsForList().leftPush("foolist", "6");
225226
operations.opsForList().range("foolist", 0l, 1l);
226227
operations.opsForSet().add("fooset", "7");
@@ -242,7 +243,7 @@ public List<Object> execute(RedisOperations operations) throws DataAccessExcepti
242243
Map<Long, Long> map = new LinkedHashMap<Long, Long>();
243244
map.put(10l, 11l);
244245
assertThat(results,
245-
isEqual(Arrays.asList(new Object[] { 5l, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
246+
isEqual(Arrays.asList(new Object[] { 5l, 1L, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
246247
}
247248

248249
@Test

0 commit comments

Comments
 (0)