diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java index 07f50d7497..bb3a472e15 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -124,7 +124,7 @@ public class ConcurrentMapCache implements Cache { @Override public ValueWrapper putIfAbsent(Object key, Object value) { - Object existing = this.store.putIfAbsent(key, value); + Object existing = this.store.putIfAbsent(key, toStoreValue(value)); return toWrapper(existing); } @@ -169,6 +169,7 @@ public class ConcurrentMapCache implements Cache { return (value != null ? new SimpleValueWrapper(fromStoreValue(value)) : null); } + @SuppressWarnings("serial") private static class NullHolder implements Serializable { } diff --git a/spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheManagerTests.java b/spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheManagerTests.java index 7e19619a7d..14fdb5472d 100644 --- a/spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheManagerTests.java +++ b/spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,18 @@ public class ConcurrentMapCacheManagerTests { assertEquals(2, cache1.get("key2").get()); cache1.put("key3", null); assertNull(cache1.get("key3").get()); + cache1.put("key3", null); + assertNull(cache1.get("key3").get()); + cache1.evict("key3"); + assertNull(cache1.get("key3")); + + assertEquals("value1", cache1.putIfAbsent("key1", "value1x").get()); + assertEquals("value1", cache1.get("key1").get()); + assertEquals(2, cache1.putIfAbsent("key2", 2.1).get()); + assertNull(cache1.putIfAbsent("key3", null)); + assertNull(cache1.get("key3").get()); + assertNull(cache1.putIfAbsent("key3", null).get()); + assertNull(cache1.get("key3").get()); cache1.evict("key3"); assertNull(cache1.get("key3")); }