You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ad...@apache.org on 2008/11/17 19:18:20 UTC

svn commit: r718309 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/fonts/FontCache.java status.xml

Author: adelmelle
Date: Mon Nov 17 10:18:20 2008
New Revision: 718309

URL: http://svn.apache.org/viewvc?rev=718309&view=rev
Log:
Bugzilla 46211:
Fixed some multi-threading issues in FontCache.java (+ some minor cleanup: simplification of conditionals)
Thanks to rogov.AT.devexperts.com for tracing and reporting the problem.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java?rev=718309&r1=718308&r2=718309&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java Mon Nov 17 10:18:20 2008
@@ -48,7 +48,7 @@
      * Serialization Version UID. Change this value if you want to make sure the user's cache
      * file is purged after an update.
      */
-    private static final long serialVersionUID = 605232520271754718L;
+    private static final long serialVersionUID = 605232520271754719L;
 
     /** logging instance */
     private static Log log = LogFactory.getLog(FontCache.class);
@@ -64,7 +64,7 @@
     private transient boolean changed = false;
 
     /** change lock */
-    private transient Object changeLock = new Object();
+    private final Object changeLock = new Object();
 
     /** master mapping of font url -> font info.  This needs to be
      *  a list, since a TTC file may contain more than 1 font. */
@@ -80,12 +80,6 @@
         //nop
     }
 
-    private void readObject(java.io.ObjectInputStream in)
-            throws IOException, ClassNotFoundException {
-        in.defaultReadObject();
-        this.changeLock = new Object(); //Initialize transient field
-    }
-
     private static File getUserHome() {
         String s = System.getProperty("user.home");
         if (s != null) {
@@ -226,10 +220,8 @@
      * @return boolean
      */
     public boolean containsFont(String embedUrl) {
-        if (embedUrl != null) {
-            return getFontFileMap().containsKey(embedUrl);
-        }
-        return false;
+        return (embedUrl != null
+                && getFontFileMap().containsKey(embedUrl));
     }
 
     /**
@@ -238,10 +230,8 @@
      * @return font
      */
     public boolean containsFont(EmbedFontInfo fontInfo) {
-        if (fontInfo != null) {
-            return getFontFileMap().containsKey(getCacheKey(fontInfo));
-        }
-        return false;
+        return (fontInfo != null
+                && getFontFileMap().containsKey(getCacheKey(fontInfo)));
     }
 
     /**
@@ -316,10 +306,7 @@
      * @return CachedFontFile object
      */
     public CachedFontFile getFontFile(String embedUrl) {
-        if (containsFont(embedUrl)) {
-            return (CachedFontFile)getFontFileMap().get(embedUrl);
-        }
-        return null;
+        return containsFont(embedUrl) ? (CachedFontFile) getFontFileMap().get(embedUrl) : null;
     }
 
     /**
@@ -362,8 +349,8 @@
      * @return whether this is a failed font
      */
     public boolean isFailedFont(String embedUrl, long lastModified) {
-        if (getFailedFontMap().containsKey(embedUrl)) {
-            synchronized (changeLock) {
+        synchronized (changeLock) {
+            if (getFailedFontMap().containsKey(embedUrl)) {
                 long failedLastModified = ((Long)getFailedFontMap().get(embedUrl)).longValue();
                 if (lastModified != failedLastModified) {
                     // this font has been changed so lets remove it
@@ -371,10 +358,11 @@
                     getFailedFontMap().remove(embedUrl);
                     changed = true;
                 }
+                return true;
+            } else {
+                return false;
             }
-            return true;
         }
-        return false;
     }
 
     /**
@@ -457,10 +445,8 @@
         }
 
         public boolean containsFont(EmbedFontInfo efi) {
-            if (efi.getPostScriptName() != null) {
-                return getFileFontsMap().containsKey(efi.getPostScriptName());
-            }
-            return false;
+            return efi.getPostScriptName() != null
+                    && getFileFontsMap().containsKey(efi.getPostScriptName());
         }
 
         public EmbedFontInfo[] getEmbedFontInfos() {

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=718309&r1=718308&r2=718309&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Mon Nov 17 10:18:20 2008
@@ -53,6 +53,15 @@
 
   <changes>
     <release version="FOP Trunk" date="TBD">
+      <action context="Code" dev="AD" type="fix" fixes-bug="46211" due-to="rogov.AT.devexperts.com">
+        Fixed some multi-threading issues in FontCache.java:
+        <ul>
+        <li>remove the unused private readObject()</li>
+        <li>make the changeLock member final (initialization-safety + impossible to reassign)</li>
+        <li>perform the HashMap check for a failed font inside the synchronized block to avoid a race condition</li>
+        </ul>
+      </action>
+      </action>
       <action context="Renderers" dev="AD" type="add" fixes-bug="45113" due-to="Alexander Stamenov">
         Added PDF /Launch action: references to URIs using the file:// protocol will now generate
         a /Launch action as opposed to a more general /URI (which doesn't yield the expected result



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org