diff --git a/org.springframework.core/src/main/java/org/springframework/util/CachingMapDecorator.java b/org.springframework.core/src/main/java/org/springframework/util/CachingMapDecorator.java
index f758e412a2f..d0a080fed68 100644
--- a/org.springframework.core/src/main/java/org/springframework/util/CachingMapDecorator.java
+++ b/org.springframework.core/src/main/java/org/springframework/util/CachingMapDecorator.java
@@ -22,6 +22,7 @@ import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
@@ -33,7 +34,7 @@ import java.util.WeakHashMap;
* A simple decorator for a Map, encapsulating the workflow for caching
* expensive values in a target Map. Supports caching weak or strong keys.
*
- *
This class is also an abstract template. Caching Map implementations
+ *
This class is an abstract template. Caching Map implementations
* should subclass and override the create(key) method which
* encapsulates expensive creation of a new object.
*
@@ -41,9 +42,9 @@ import java.util.WeakHashMap;
* @author Juergen Hoeller
* @since 1.2.2
*/
-public class CachingMapDecorator implements Map, Serializable {
+public abstract class CachingMapDecorator implements Map, Serializable {
- protected static Object NULL_VALUE = new Object();
+ private static Object NULL_VALUE = new Object();
private final Map targetMap;
@@ -150,7 +151,16 @@ public class CachingMapDecorator implements Map, Serializable {
}
public V remove(Object key) {
- return unwrapIfNecessary(this.targetMap.remove(key));
+ return unwrapReturnValue(this.targetMap.remove(key));
+ }
+
+ @SuppressWarnings("unchecked")
+ private V unwrapReturnValue(Object value) {
+ Object returnValue = value;
+ if (returnValue instanceof Reference) {
+ returnValue = ((Reference) returnValue).get();
+ }
+ return (returnValue == NULL_VALUE ? null : (V) returnValue);
}
public void putAll(Map extends K, ? extends V> map) {
@@ -186,8 +196,16 @@ public class CachingMapDecorator implements Map, Serializable {
@SuppressWarnings("unchecked")
private Collection valuesCopy() {
LinkedList values = new LinkedList();
- for (Object value : this.targetMap.values()) {
- values.add(value instanceof Reference ? ((Reference) value).get() : (V) value);
+ for (Iterator