diff options
author | Sven Gothel <[email protected]> | 2019-12-31 04:33:38 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-31 04:33:38 +0100 |
commit | add34060fde735ea932ca49fbe79e473c5a4f40b (patch) | |
tree | a81c181f2df64b5562efd0420031172501bc5a18 /src | |
parent | 178c7b9d40e06a04790542241912ca21d2c7b92f (diff) |
WeakIdentityHashMap: Always null check on weakRef.get(); IdentityWeakReference: hash is final.
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/jogamp/common/util/WeakIdentityHashMap.java | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/java/com/jogamp/common/util/WeakIdentityHashMap.java b/src/java/com/jogamp/common/util/WeakIdentityHashMap.java index fd865ba..b3b5bc0 100644 --- a/src/java/com/jogamp/common/util/WeakIdentityHashMap.java +++ b/src/java/com/jogamp/common/util/WeakIdentityHashMap.java @@ -172,24 +172,26 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V> { final Set<Map.Entry<K, V>> ret = new HashSet<>(); for (final Map.Entry<IdentityWeakReference<K>, V> ref : backingStore.entrySet()) { final K key = ref.getKey().get(); - final V value = ref.getValue(); - final Map.Entry<K, V> entry = new Map.Entry<K, V>() { - @Override - public K getKey() { - return key; - } + if( null != key ) { + final V value = ref.getValue(); + final Map.Entry<K, V> entry = new Map.Entry<K, V>() { + @Override + public K getKey() { + return key; + } - @Override - public V getValue() { - return value; - } + @Override + public V getValue() { + return value; + } - @Override - public V setValue(final V value) { - throw new UnsupportedOperationException(); - } - }; - ret.add(entry); + @Override + public V setValue(final V value) { + throw new UnsupportedOperationException(); + } + }; + ret.add(entry); + } } return Collections.unmodifiableSet(ret); } @@ -199,7 +201,10 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V> { reap(); final Set<K> ret = new HashSet<>(); for (final IdentityWeakReference<K> ref : backingStore.keySet()) { - ret.add(ref.get()); + final K key = ref.get(); + if( null != key ) { + ret.add(key); + } } return Collections.unmodifiableSet(ret); } @@ -283,7 +288,7 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V> { } private static class IdentityWeakReference<K> extends WeakReference<K> { - int hash; + final int hash; IdentityWeakReference(final K obj, final ReferenceQueue<K> q) { super(obj, q); |