Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 38068 invoked from network); 24 Nov 2002 17:32:04 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 24 Nov 2002 17:32:04 -0000 Received: (qmail 4600 invoked by uid 97); 24 Nov 2002 17:33:05 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 4573 invoked by uid 97); 24 Nov 2002 17:33:04 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 4557 invoked by uid 98); 24 Nov 2002 17:33:04 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: <009b01c293df$aea47a00$9e2529d9@oemcomputer> From: "Stephen Colebourne" To: , "Jakarta Commons Users List" Cc: "Jakarta Commons Developers List" References: <20021119005400.77658.qmail@web11002.mail.yahoo.com> Subject: Re: [Collections] SoftRefHashMap.purge throws ConcurrentModificationException Date: Sun, 24 Nov 2002 17:34:01 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N I have applied the suggested fix, as it appears to be sensible, thanks. However, we now advise using ReferenceMap instead of SoftRefHashMap, as the latter is severly broken. Stephen ----- Original Message ----- From: "Eduardo Francos" > I'm using the SoftRefHashMap to manage images and I get a > ConcurrentModificationException when I call the purge method. > Looking at the code I found that the method removes GCed references > directly from the Map instead of using the iterator's remove method. > I subclassed SoftRefHashMap and implemented the following change in > purge that works. > > public void purge() > { > Map map = getMap(); > Set keys = map.keySet(); > if (keys == null) { > return; > } > for (Iterator i = keys.iterator(); i.hasNext(); ) { > Object key = (Object)i.next(); > Reference ref = (Reference)map.get(key); > if (ref.get() == null) { > // Fix for ConcurrentModificationException > // Previously: > // map.remove( key ); > i.remove(); > // end ConcurrentModificationException fix > } > } > } > > Either I was doing something wrong or the fix is required. > > Eduardo > > > > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > -- To unsubscribe, e-mail: For additional commands, e-mail: