Return-Path: Delivered-To: apmail-xmlgraphics-commits-archive@www.apache.org Received: (qmail 98151 invoked from network); 18 Sep 2009 14:15:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Sep 2009 14:15:18 -0000 Received: (qmail 23040 invoked by uid 500); 18 Sep 2009 14:15:17 -0000 Mailing-List: contact commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: general@xmlgraphics.apache.org Delivered-To: mailing list commits@xmlgraphics.apache.org Received: (qmail 23031 invoked by uid 99); 18 Sep 2009 14:15:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2009 14:15:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2009 14:15:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0428E23888CD; Fri, 18 Sep 2009 14:14:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r816640 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java Date: Fri, 18 Sep 2009 14:14:55 -0000 To: commits@xmlgraphics.apache.org From: maxberger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090918141456.0428E23888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: maxberger Date: Fri Sep 18 14:14:55 2009 New Revision: 816640 URL: http://svn.apache.org/viewvc?rev=816640&view=rev Log: removed ConcurrentModificationException from ImageCache (bugzilla #47868). TestCase thanks to mercuron@gmx.ch Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java?rev=816640&r1=816639&r2=816640&view=diff ============================================================================== --- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java (original) +++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java Fri Sep 18 14:14:55 2009 @@ -22,8 +22,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Set; import javax.xml.transform.Source; @@ -144,22 +146,22 @@ * @return true if the URI is invalid */ public boolean isInvalidURI(String uri) { - Long timestamp = (Long)invalidURIs.get(uri); - if (timestamp != null) { - boolean expired = removeInvalidURIIfExpired(uri, timestamp.longValue()); - if (!expired) { - if (cacheListener != null) { - cacheListener.invalidHit(uri); - } - return true; + boolean expired = removeInvalidURIIfExpired(uri); + if (expired) { + return false; + } else { + if (cacheListener != null) { + cacheListener.invalidHit(uri); } + return true; } - return false; } - private boolean removeInvalidURIIfExpired(String uri, long timestamp) { - boolean expired = this.invalidURIExpirationPolicy.isExpired( - this.timeStampProvider, timestamp); + private boolean removeInvalidURIIfExpired(String uri) { + Long timestamp = (Long) invalidURIs.get(uri); + boolean expired = (timestamp == null) + || this.invalidURIExpirationPolicy.isExpired( + this.timeStampProvider, timestamp.longValue()); if (expired) { this.invalidURIs.remove(uri); } @@ -288,12 +290,11 @@ } private void doInvalidURIHouseKeeping() { - synchronized(this.invalidURIs) { - Iterator iter = this.invalidURIs.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry)iter.next(); - removeInvalidURIIfExpired((String)entry.getKey(), ((Long)entry.getValue()).longValue()); - } + final Set currentEntries = new HashSet(this.invalidURIs.keySet()); + final Iterator iter = currentEntries.iterator(); + while (iter.hasNext()) { + final String key = (String) iter.next(); + removeInvalidURIIfExpired(key); } } Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java?rev=816640&r1=816639&r2=816640&view=diff ============================================================================== --- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java (original) +++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java Fri Sep 18 14:14:55 2009 @@ -177,4 +177,21 @@ assertEquals(1, statistics.getImageCacheMisses()); } + + /** + * Test to check if doInvalidURIHouseKeeping() throws a + * ConcurrentModificationException. + */ + public void testImageCacheHouseKeeping() { + ImageCache imageCache = new ImageCache(new TimeStampProvider(), + new DefaultExpirationPolicy(1)); + imageCache.registerInvalidURI("invalid"); + imageCache.registerInvalidURI("invalid2"); + try { + Thread.sleep(1200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + imageCache.doHouseKeeping(); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: commits-help@xmlgraphics.apache.org