felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1388007 - /felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
Date Thu, 20 Sep 2012 12:58:25 GMT
Author: clement
Date: Thu Sep 20 12:58:24 2012
New Revision: 1388007

URL: http://svn.apache.org/viewvc?rev=1388007&view=rev
Log:
Fix FELIX-3672
Protect the m_attached and m_idle fields against concurrent access while iterating over them

Modified:
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java?rev=1388007&r1=1388006&r2=1388007&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceCreator.java
Thu Sep 20 12:58:24 2012
@@ -109,13 +109,20 @@ public class InstanceCreator implements 
      */
     void removeInstancesFromBundle(long bundle) {
         // Disposes instance from attached instances
-        Collection col = m_attached.keySet();
+        Map copy = null;
+
+        // To avoid concurrent modification exception, we create a copy.
+        synchronized (this) {
+            copy = new HashMap(m_attached);
+        }
+
+        Collection col = copy.keySet();
         Iterator iterator = col.iterator();
         List instanceToRemove = new ArrayList();
         List factoryToRemove = new ArrayList();
         while (iterator.hasNext()) {
             IPojoFactory factory = (IPojoFactory) iterator.next();
-            List list = (List) m_attached.get(factory);
+            List list = (List) copy.get(factory);
             for (int i = 0; i < list.size(); i++) {
                 ManagedInstance managed = (ManagedInstance) list.get(i);
                 if (managed.m_bundleId == bundle) {
@@ -132,14 +139,19 @@ public class InstanceCreator implements 
             }
         }
 
+        // We remove from the original map
         for (int i = 0; i < factoryToRemove.size(); i++) {
             m_attached.remove(factoryToRemove.get(i));
         }
 
         // Delete idle instances
+        List list = null;
+        synchronized (this) {
+            list = new ArrayList(m_idle);
+        }
         instanceToRemove.clear();
-        for (int i = 0; i < m_idle.size(); i++) {
-            ManagedInstance managed = (ManagedInstance) m_idle.get(i);
+        for (int i = 0; i < list.size(); i++) {
+            ManagedInstance managed = (ManagedInstance) list.get(i);
             if (managed.m_bundleId == bundle) {
                 instanceToRemove.add(managed);
             }



Mime
View raw message