CacheMap may have spurious null keys
@@ -73,27 +73,34 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V> {
Set<Map.Entry<K, V>> ret = new HashSet<Map.Entry<K, V>>();
for (Map.Entry<IdentityWeakReference, V> ref : backingStore.entrySet()) {
final K key = ref.getKey().get();
+ if (key != null) {
final V value = ref.getValue();
Map.Entry<K, V> entry = new Map.Entry<K, V>() {
public K getKey() {
return key;
}
+
public V getValue() {
return value;
}
+
public V setValue(V value) {
throw new UnsupportedOperationException();
}
};
ret.add(entry);
}
+ }
return Collections.unmodifiableSet(ret);
}
public Set<K> keySet() {
reap();
Set<K> ret = new HashSet<>();
for (IdentityWeakReference ref : backingStore.keySet()) {
- ret.add(ref.get());
+ K key = ref.get();
+ if (key != null) {
+ ret.add(key);
+ }
}
return Collections.unmodifiableSet(ret);
}
