commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chen (Jira)" <>
Subject [jira] [Issue Comment Deleted] (COLLECTIONS-663) Unexpected ConcurrentModificationException when altering Collection of a MultiValuedMap
Date Tue, 05 Nov 2019 01:33:00 GMT


Chen updated COLLECTIONS-663:
    Comment: was deleted

(was: Hi,[~ggregory]

Read the code, In the,

1、AbstractMultiValuedMap.MapIterator() methos will return private MultiValuedMapIterator

2、MultiValuedMapIterator class will call AbstractMultiValuedMap.entries().iterator()

3、AbstractMultiValuedMap.entries() will return private EntryValues class

4、EntryValues class will return LazyIteratorChain overide nextIterator which call MultiValuedMapEntry

5、MultiValuedMapEntry class setValue() method throw UnsupportedOperationException. 

so MapIterator.setValue() is not support!

Ithink it is a proplem, Should we solve this problem by submitting a PR?)

> Unexpected ConcurrentModificationException when altering Collection of a MultiValuedMap
> ---------------------------------------------------------------------------------------
>                 Key: COLLECTIONS-663
>                 URL:
>             Project: Commons Collections
>          Issue Type: Bug
>            Reporter: Christophe Schmaltz
>            Assignee: Bruno P. Kinoshita
>            Priority: Trivial
> Testcase:
> {code}	@Test
> 	public void test() {
> 		MultiValuedMap<Integer, Integer> multiMap = new HashSetValuedHashMap<>();
> 		multiMap.put(1, 10);
> 		multiMap.put(2, 20);
> 		for (Collection<Integer> innerCollection : multiMap.asMap().values()) {
> 			for (Iterator<Integer> iterator = innerCollection.iterator(); iterator.hasNext();)
> 				Integer i =;
> 				iterator.remove(); // only the innerCollection is altered
> 			}
> 			// innerCollection.add(6); // adding stuff back should also work...
> 		}
> 	}{code}
> This test unexpectedly throws a ConcurrentModificationException.
> The issue is that when calling {{iterator.remove()}} the {{AbstractMultiValuedMap.ValuesIterator}}
detects that the Collection is empty and calls {{AbstractMultiValuedMap.this.remove(key);}}.
> It may be better if the iterator of the inner collection had a reference on the iterator
if the outer map and called {{containerIterator.remove()}} instead.
> *Note:* this solution would again present issues if the user tries to add new elements
in this now empty collection (which was removed from the parent).
> In the current state, it is quite unclear why an exception is thrown, without debugging
the code. 

This message was sent by Atlassian Jira

View raw message