Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5E6E7200D32 for ; Sun, 5 Nov 2017 14:21:05 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5CEC21609EA; Sun, 5 Nov 2017 13:21:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7BAA8160BEB for ; Sun, 5 Nov 2017 14:21:04 +0100 (CET) Received: (qmail 25061 invoked by uid 500); 5 Nov 2017 13:21:03 -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 25044 invoked by uid 99); 5 Nov 2017 13:21:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Nov 2017 13:21:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id CDBC6180890 for ; Sun, 5 Nov 2017 13:21:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id DlxAOLy04MtE for ; Sun, 5 Nov 2017 13:21:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 37CDF5F30B for ; Sun, 5 Nov 2017 13:21:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A3E9DE0D60 for ; Sun, 5 Nov 2017 13:21:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 253162419F for ; Sun, 5 Nov 2017 13:21:00 +0000 (UTC) Date: Sun, 5 Nov 2017 13:21:00 +0000 (UTC) From: "Christophe Schmaltz (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (COLLECTIONS-663) Unexpected ConcurrentModificationException when altering Collection of a MultiValuedMap MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 05 Nov 2017 13:21:05 -0000 [ https://issues.apache.org/jira/browse/COLLECTIONS-663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16239524#comment-16239524 ] Christophe Schmaltz edited comment on COLLECTIONS-663 at 11/5/17 1:20 PM: -------------------------------------------------------------------------- Thank you for your response. I once used the {{MapIterator}}, sadly I found out that it doesn't support what I try to achieve: {code} @Test public void testWhatINeedToWork() { // ArrayListValuedHashMap multiMap = new ArrayListValuedHashMap<>(); MultiValuedMap multiMap = new HashSetValuedHashMap<>(); multiMap.put(1, 10); multiMap.put(1, 11); multiMap.put(2, 20); Iterator it = multiMap.mapIterator(); for (MapIterator iterator = multiMap.mapIterator(); iterator.hasNext();) { iterator.next(); Integer value = iterator.getValue(); if ((value % 2) == 0) { // Integer is immutable, we need to replace using setValue(.) iterator.setValue(value * 2); } } }{code} My issue was that {{MapIterator.setValue(.)}} is not supported. (My current workaround is storing the elements I need to change in a list, and pushing them back in the map afterwards) I understand the difficulty in implementing it for {{HashSetValuedHashMap}} though, as the {{HashSet.iterator}} doesn't support it either (sadly, that's what I need). I observed that {{ArrayListValuedHashMap}} doesn't support {{setValue(.)}} either (should be possible, as {{ArrayList.listIterator}} has this feature. was (Author: chris333): Than you for your response. I once used the {{MapIterator}}, sadly I found out that it doesn't support what I try to achieve: {code} @Test public void testWhatINeedToWork() { // ArrayListValuedHashMap multiMap = new ArrayListValuedHashMap<>(); MultiValuedMap multiMap = new HashSetValuedHashMap<>(); multiMap.put(1, 10); multiMap.put(1, 11); multiMap.put(2, 20); Iterator it = multiMap.mapIterator(); for (MapIterator iterator = multiMap.mapIterator(); iterator.hasNext();) { iterator.next(); Integer value = iterator.getValue(); if ((value % 2) == 0) { // Integer is immutable, we need to replace using setValue(.) iterator.setValue(value * 2); } } }{code} My issue was that {{MapIterator.setValue(.)}} is not supported. (My current workaround is storing the elements I need to change in a list, and pushing them back in the map afterwards) I understand the difficulty in implementing it for {{HashSetValuedHashMap}} though, as the {{HashSet.iterator}} doesn't support it either (sadly, that's what I need). I observed that {{ArrayListValuedHashMap}} doesn't support {{setValue(.)}} either (should be possible, as {{ArrayList.listIterator}} has this feature. > 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 > > Testcase: > {code} @Test > public void test() { > MultiValuedMap multiMap = new HashSetValuedHashMap<>(); > multiMap.put(1, 10); > multiMap.put(2, 20); > for (Collection innerCollection : multiMap.asMap().values()) { > for (Iterator 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 (v6.4.14#64029)