You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/04/29 13:06:00 UTC

[jira] [Work logged] (COLLECTIONS-663) Unexpected ConcurrentModificationException when altering Collection of a MultiValuedMap

     [ https://issues.apache.org/jira/browse/COLLECTIONS-663?focusedWorklogId=428547&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-428547 ]

ASF GitHub Bot logged work on COLLECTIONS-663:
----------------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Apr/20 13:04
            Start Date: 29/Apr/20 13:04
    Worklog Time Spent: 10m 
      Work Description: garydgregory commented on a change in pull request #110:
URL: https://github.com/apache/commons-collections/pull/110#discussion_r417296559



##########
File path: src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java
##########
@@ -879,7 +879,8 @@ public boolean remove(final Object o) {
             public Map.Entry<K, Collection<V>> next() {
                 final Map.Entry<K, Collection<V>> entry = super.next();
                 final K key = entry.getKey();
-                return new UnmodifiableMapEntry<>(key, wrappedCollection(key));
+                final Collection<V> value = entry.getValue();
+                return new UnmodifiableMapEntry<>(key, value);

Review comment:
       You can just inline `key` and `value` IMO.




----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 428547)
    Time Spent: 20m  (was: 10m)

> Unexpected ConcurrentModificationException when altering Collection of a MultiValuedMap
> ---------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-663
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-663
>             Project: Commons Collections
>          Issue Type: Bug
>            Reporter: Christophe Schmaltz
>            Assignee: Bruno P. Kinoshita
>            Priority: Trivial
>          Time Spent: 20m
>  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.next();
> 				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
(v8.3.4#803005)