8163353: NPE in ConcurrentHashMap.removeAll()
Reviewed-by: martin, psandoz, redestad, alanb
This commit is contained in:
parent
34565b8ada
commit
4c999ed180
@ -4566,7 +4566,10 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
|
||||
boolean modified = false;
|
||||
// Use (c instanceof Set) as a hint that lookup in c is as
|
||||
// efficient as this view
|
||||
if (c instanceof Set<?> && c.size() > map.table.length) {
|
||||
Node<K,V>[] t;
|
||||
if ((t = map.table) == null) {
|
||||
return false;
|
||||
} else if (c instanceof Set<?> && c.size() > t.length) {
|
||||
for (Iterator<?> it = iterator(); it.hasNext(); ) {
|
||||
if (c.contains(it.next())) {
|
||||
it.remove();
|
||||
|
@ -359,6 +359,21 @@ public class ConcurrentHashMapTest extends JSR166TestCase {
|
||||
assertTrue(s.contains(five));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test keySet().removeAll on empty map
|
||||
*/
|
||||
public void testKeySet_empty_removeAll() {
|
||||
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
|
||||
Set<Integer> set = map.keySet();
|
||||
set.removeAll(Collections.emptyList());
|
||||
assertTrue(map.isEmpty());
|
||||
assertTrue(set.isEmpty());
|
||||
// following is test for JDK-8163353
|
||||
set.removeAll(Collections.emptySet());
|
||||
assertTrue(map.isEmpty());
|
||||
assertTrue(set.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* keySet.toArray returns contains all keys
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user