From issues-return-80366-apmail-commons-issues-archive=commons.apache.org@commons.apache.org Tue Nov 5 01:33:03 2019 Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id D126E19BC6 for ; Tue, 5 Nov 2019 01:33:02 +0000 (UTC) Received: (qmail 79390 invoked by uid 500); 5 Nov 2019 01:33:01 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 79319 invoked by uid 500); 5 Nov 2019 01:33:01 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 79306 invoked by uid 99); 5 Nov 2019 01:33:01 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Nov 2019 01:33:01 +0000 Received: from jira-he-de.apache.org (static.172.67.40.188.clients.your-server.de [188.40.67.172]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id D41D9E30F8 for ; Tue, 5 Nov 2019 01:33:00 +0000 (UTC) Received: from jira-he-de.apache.org (localhost.localdomain [127.0.0.1]) by jira-he-de.apache.org (ASF Mail Server at jira-he-de.apache.org) with ESMTP id 321E2780559 for ; Tue, 5 Nov 2019 01:33:00 +0000 (UTC) Date: Tue, 5 Nov 2019 01:33:00 +0000 (UTC) From: "Chen (Jira)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Issue Comment Deleted] (COLLECTIONS-663) Unexpected ConcurrentModificationException when altering Collection of a MultiValuedMap MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/COLLECTIONS-663?page=3Dcom.atl= assian.jira.plugin.system.issuetabpanels:all-tabpanel ] Chen updated COLLECTIONS-663: ----------------------------- Comment: was deleted (was: Hi,[~ggregory] Read the code, In the AbstractMultiValuedMap.java, 1=E3=80=81AbstractMultiValuedMap.MapIterator() methos will return private M= ultiValuedMapIterator class 2=E3=80=81MultiValuedMapIterator class will call AbstractMultiValuedMap.ent= ries().iterator() 3=E3=80=81AbstractMultiValuedMap.entries() will return private EntryValues = class 4=E3=80=81EntryValues class will return=C2=A0LazyIteratorChain overide next= Iterator which call MultiValuedMapEntry class 5=E3=80=81MultiValuedMapEntry class setValue() method throw=C2=A0Unsupporte= dOperationException.=C2=A0 so MapIterator.setValue() is not support! Ithink it is a proplem,=C2=A0Should we solve this problem by submitting a P= R?) > Unexpected ConcurrentModificationException when altering Collection of a = MultiValuedMap > -------------------------------------------------------------------------= -------------- > > Key: COLLECTIONS-663 > URL: https://issues.apache.org/jira/browse/COLLECTIONS-66= 3 > Project: Commons Collections > Issue Type: Bug > Reporter: Christophe Schmaltz > Assignee: Bruno P. Kinoshita > Priority: Trivial > > Testcase: > {code}=09@Test > =09public void test() { > =09=09MultiValuedMap multiMap =3D new HashSetValuedHash= Map<>(); > =09=09multiMap.put(1, 10); > =09=09multiMap.put(2, 20); > =09=09for (Collection innerCollection : multiMap.asMap().values(= )) { > =09=09=09for (Iterator iterator =3D innerCollection.iterator(); = iterator.hasNext();) { > =09=09=09=09Integer i =3D iterator.next(); > =09=09=09=09iterator.remove(); // only the innerCollection is altered > =09=09=09} > =09=09=09// innerCollection.add(6); // adding stuff back should also work= ... > =09=09} > =09}{code} > This test unexpectedly throws a ConcurrentModificationException. > The issue is that when calling {{iterator.remove()}} the {{AbstractMultiV= aluedMap.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 pare= nt). > In the current state, it is quite unclear why an exception is thrown, wit= hout debugging the code.=20 -- This message was sent by Atlassian Jira (v8.3.4#803005)