You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by dv...@apache.org on 2007/03/25 19:04:49 UTC

svn commit: r522302 - /xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/DOMTreeManager.java

Author: dvholten
Date: Sun Mar 25 10:04:48 2007
New Revision: 522302

URL: http://svn.apache.org/viewvc?view=rev&rev=522302
Log:
fix bug #40686. thanks bernd fechner for the analysis

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/DOMTreeManager.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/DOMTreeManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/DOMTreeManager.java?view=diff&rev=522302&r1=522301&r2=522302
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/DOMTreeManager.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/DOMTreeManager.java Sun Mar 25 10:04:48 2007
@@ -23,6 +23,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.ArrayList;
+import java.util.Collections;
 
 import org.apache.batik.ext.awt.g2d.GraphicContext;
 import org.w3c.dom.Comment;
@@ -70,9 +71,10 @@
 
     /**
      * Set of group managers that build groups for
-     * this manager
+     * this manager.
+     * The synchronizedList is part of the fix for bug #40686
      */
-    protected List groupManagers = new ArrayList();
+    protected final List groupManagers = Collections.synchronizedList( new ArrayList() );
 
     /**
      * Set of definitions that are to be placed at the top of the
@@ -171,11 +173,16 @@
      */
     public void appendGroup(Element group, DOMGroupManager groupManager){
         topLevelGroup.appendChild(group);
-        int nManagers = groupManagers.size();
-        for(int i=0; i<nManagers; i++){
-            DOMGroupManager gm = (DOMGroupManager)groupManagers.get(i);
-            if( gm != groupManager )
-                gm.recycleCurrentGroup();
+        synchronized( groupManagers ){
+            // we want to prevent that the groupManagers-list changes while
+            // we iterate over it. If that would happen, we might skip entries
+            // within the list or ignore new entries at the end. Fix #40686
+            int nManagers = groupManagers.size();
+            for(int i=0; i<nManagers; i++){
+                DOMGroupManager gm = (DOMGroupManager)groupManagers.get(i);
+                if( gm != groupManager )
+                    gm.recycleCurrentGroup();
+            }
         }
     }
 
@@ -192,10 +199,15 @@
      */
     protected void recycleTopLevelGroup(boolean recycleConverters){
         // First, recycle group managers
-        int nManagers = groupManagers.size();
-        for(int i=0; i<nManagers; i++){
-            DOMGroupManager gm = (DOMGroupManager)groupManagers.get(i);
-            gm.recycleCurrentGroup();
+        synchronized( groupManagers ){
+            // we want to prevent that the groupManagers-list changes while
+            // we iterate over it. If that would happen, we might skip entries
+            // within the list or ignore new entries at the end. Fix #40686
+            int nManagers = groupManagers.size();
+            for(int i=0; i<nManagers; i++){
+                DOMGroupManager gm = (DOMGroupManager)groupManagers.get(i);
+                gm.recycleCurrentGroup();
+            }
         }
 
         // Create top level group node