From a0eb30d9a19d8f0f41baafaaf40e890d988489bb Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Wed, 26 Mar 2014 13:37:35 +0100 Subject: [PATCH 1/2] DATAREDIS-289 - Avoid NPE in append() in case of pipelining or/and multi/exec calls. Prepare issue branch. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f09fb8eb53..bcc0a08cdd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ jredisVersion=06052013 jedisVersion=2.4.1 springVersion=3.2.8.RELEASE log4jVersion=1.2.17 -version=1.3.0.BUILD-SNAPSHOT +version=1.3.0.DATAREDIS-289-SNAPSHOT srpVersion=0.7 jacksonVersion=1.8.8 fasterXmlJacksonVersion=2.2.0 From ecc03a57326b05574a57541dfbb0a3f214de75a7 Mon Sep 17 00:00:00 2001 From: reta Date: Wed, 26 Mar 2014 13:46:17 +0100 Subject: [PATCH 2/2] DATAREDIS-289 - Avoid NPE in 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. --- .../data/redis/core/DefaultValueOperations.java | 3 ++- .../springframework/data/redis/core/RedisTemplateTests.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java index bdfaf8d2c3..6d3952c223 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java @@ -84,7 +84,8 @@ public Integer append(K key, String value) { return execute(new RedisCallback() { public Integer doInRedis(RedisConnection connection) { - return connection.append(rawKey, rawString).intValue(); + final Long result = connection.append(rawKey, rawString); + return ( result != null ) ? result.intValue() : null; } }, true); } diff --git a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java b/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java index 82f9cb4b3d..61b0f09271 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java @@ -218,6 +218,7 @@ public List execute(RedisOperations operations) throws DataAccessExcepti operations.multi(); operations.opsForValue().set("foo", "5"); operations.opsForValue().get("foo"); + operations.opsForValue().append("foo1", "5"); operations.opsForList().leftPush("foolist", "6"); operations.opsForList().range("foolist", 0l, 1l); operations.opsForSet().add("fooset", "7"); @@ -239,7 +240,7 @@ public List execute(RedisOperations operations) throws DataAccessExcepti Map map = new LinkedHashMap(); map.put(10l, 11l); assertThat(results, - isEqual(Arrays.asList(new Object[] { 5l, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map }))); + isEqual(Arrays.asList(new Object[] { 5l, 1L, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map }))); } @Test