Skip to content

Commit aa739f4

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 f366ffc commit aa739f4

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
@@ -84,7 +84,8 @@ public Integer append(K key, String value) {
8484
return execute(new RedisCallback<Integer>() {
8585

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ public List<Object> execute(RedisOperations operations) throws DataAccessExcepti
218218
operations.multi();
219219
operations.opsForValue().set("foo", "5");
220220
operations.opsForValue().get("foo");
221+
operations.opsForValue().append("foo1", "5");
221222
operations.opsForList().leftPush("foolist", "6");
222223
operations.opsForList().range("foolist", 0l, 1l);
223224
operations.opsForSet().add("fooset", "7");
@@ -239,7 +240,7 @@ public List<Object> execute(RedisOperations operations) throws DataAccessExcepti
239240
Map<Long, Long> map = new LinkedHashMap<Long, Long>();
240241
map.put(10l, 11l);
241242
assertThat(results,
242-
isEqual(Arrays.asList(new Object[] { 5l, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
243+
isEqual(Arrays.asList(new Object[] { 5l, 1L, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
243244
}
244245

245246
@Test

0 commit comments

Comments
 (0)