From c25cfdb70197973af46e6056e6db1830dd8692a9 Mon Sep 17 00:00:00 2001
From: Thomas Oster <thomas.oster@rwth-aachen.de>
Date: Mon, 25 Mar 2013 13:12:15 +0100
Subject: [PATCH] Fix ConcurrentModificationException

---
 .../liblasercut/TimeIntensiveOperation.java   | 30 ++++++++++++-------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/com/t_oster/liblasercut/TimeIntensiveOperation.java b/src/com/t_oster/liblasercut/TimeIntensiveOperation.java
index 59196bf..c8ce91a 100644
--- a/src/com/t_oster/liblasercut/TimeIntensiveOperation.java
+++ b/src/com/t_oster/liblasercut/TimeIntensiveOperation.java
@@ -30,40 +30,48 @@ import java.util.List;
 public abstract class TimeIntensiveOperation
 {
 
-  private List<ProgressListener> listeners = null;
+  private final List<ProgressListener> listeners = new LinkedList<ProgressListener>();
 
   private List<ProgressListener> getListeners()
   {
-    if (listeners == null)
-    {
-      listeners = new LinkedList<ProgressListener>();
-    }
     return listeners;
   }
 
   public void addProgressListener(ProgressListener l)
   {
-    getListeners().add(l);
+    synchronized(listeners)
+    {
+      getListeners().add(l);
+    }
   }
 
   public void removeProgressListener(ProgressListener l)
   {
-    getListeners().remove(l);
+    synchronized(listeners)
+    {
+      getListeners().remove(l);
+    }
   }
 
   public void fireProgressChanged(int progress)
   {
-    for (ProgressListener l : getListeners())
+    synchronized(listeners)
     {
-      l.progressChanged(this, progress);
+      for (ProgressListener l : getListeners())
+      {
+        l.progressChanged(this, progress);
+      }
     }
   }
 
   public void fireTaskChanged(String name)
   {
-    for (ProgressListener l : getListeners())
+    synchronized(listeners)
     {
-      l.taskChanged(this, name);
+      for (ProgressListener l : getListeners())
+      {
+        l.taskChanged(this, name);
+      }
     }
   }
   private int progress = 0;
-- 
GitLab