Skip to content

NBHM/Long/Identity keySet() iterator only removes keys if values have not changed #335

@nitsanw

Description

@nitsanw

E.g.

_sschm.putIfMatch( _prevK, TOMBSTONE, _prevV );
:

    public void remove() {
      if( _prevV == null ) throw new IllegalStateException();
      _sschm.putIfMatch( _prevK, TOMBSTONE, _prevV ); // !!! tries to match with old value
      _prevV = null;
    }

This means that the following fails:

    private void testKeySetIteratorRemoveKeyAfterValChange(Map<Long, String> map, Long testKey) {
        map.put(testKey, "0");
        assertEquals("0", map.get(testKey));
        assertEquals(1, map.size());
        assertTrue(!map.isEmpty());
        assertTrue(map.containsKey(testKey));
        assertTrue(map.containsValue("0"));
        Iterator<Long> iterator = map.keySet().iterator();
        map.put(testKey, "1");
        
        while (iterator.hasNext()) {
            long key = iterator.next();
            if (key == testKey) {
                iterator.remove(); // !!! current impl does not remove the key !!!
                break;
            }
        }
        assertEquals(null, map.get(testKey));
        assertEquals(0, map.size());
        assertTrue(map.isEmpty());
        assertTrue(!map.containsKey(testKey));
        assertTrue(!map.containsValue("1"));
    }

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions