commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (Jira)" <>
Subject [jira] [Work logged] (COLLECTIONS-663) Unexpected ConcurrentModificationException when altering Collection of a MultiValuedMap
Date Wed, 06 Nov 2019 07:24:00 GMT


ASF GitHub Bot logged work on COLLECTIONS-663:

                Author: ASF GitHub Bot
            Created on: 06/Nov/19 07:23
            Start Date: 06/Nov/19 07:23
    Worklog Time Spent: 10m 
      Work Description: dota17 commented on pull request #110:  [COLLECTIONS-663] Update AbstractMultiValuedMap
   I think the representation of Multimap is {1: A, 1: B, 2: C}. So when A and B are deleted,
only {2: C} is left. And asMap() method  returns a map in the form of {1:[A, B], 2:[C]}.
In this map, {1:[], 2:[C]} is left when A and B are deleted. So wrappedCollection(key) should
not be used。 It willl show as {1: A, 1: B, 2: C} when wrappedCollection(key) is used, and
the asMap() method does not make sense.
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

Issue Time Tracking

            Worklog Id:     (was: 339205)
    Remaining Estimate: 0h
            Time Spent: 10m

> 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
>          Time Spent: 10m
>  Remaining Estimate: 0h
> 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