ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r328166 - /ant/core/trunk/src/main/org/apache/tools/ant/Project.java
Date Mon, 24 Oct 2005 22:14:56 GMT
Author: mbenson
Date: Mon Oct 24 15:14:53 2005
New Revision: 328166

URL: http://svn.apache.org/viewcvs?rev=328166&view=rev
Log:
Revert previous change; apparently I am unhinged because I can't see how it's
happening but I'm getting ConcurrentModificationExceptions willy-nilly.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/Project.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Project.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/Project.java?rev=328166&r1=328165&r2=328166&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Project.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Project.java Mon Oct 24 15:14:53 2005
@@ -324,12 +324,18 @@
      * be notified of build events for this project.
      *
      * @param listener The listener to add to the list.
-     *                 Ignored if <code>null</code>.
+     *                 Must not be <code>null</code>.
      */
     public synchronized void addBuildListener(BuildListener listener) {
-        if (!(listener == null || listeners.contains(listener))) {
-            listeners.add(listener);
+        // If the listeners already has this listener, do nothing
+        if (listeners.contains(listener)) {
+            return;
         }
+        // create a new Vector to avoid ConcurrentModificationExc when
+        // the listeners get added/removed while we are in fire
+        Vector newListeners = getBuildListeners();
+        newListeners.addElement(listener);
+        listeners = newListeners;
     }
 
     /**
@@ -340,7 +346,11 @@
      *                 Should not be <code>null</code>.
      */
     public synchronized void removeBuildListener(BuildListener listener) {
-        listeners.remove(listener);
+        // create a new Vector to avoid ConcurrentModificationExc when
+        // the listeners get added/removed while we are in fire
+        Vector newListeners = getBuildListeners();
+        newListeners.removeElement(listener);
+        listeners = newListeners;
     }
 
     /**
@@ -1837,7 +1847,7 @@
      * Send a &quot;build started&quot; event
      * to the build listeners for this project.
      */
-    public synchronized void fireBuildStarted() {
+    public void fireBuildStarted() {
         BuildEvent event = new BuildEvent(this);
         Iterator iter = listeners.iterator();
         while (iter.hasNext()) {
@@ -1853,7 +1863,7 @@
      *                  failure. May be <code>null</code>, indicating
      *                  a successful build.
      */
-    public synchronized void fireBuildFinished(Throwable exception) {
+    public void fireBuildFinished(Throwable exception) {
         BuildEvent event = new BuildEvent(this);
         event.setException(exception);
         Iterator iter = listeners.iterator();
@@ -1869,7 +1879,7 @@
      *
      * @since Ant 1.6.2
      */
-    public synchronized void fireSubBuildStarted() {
+    public void fireSubBuildStarted() {
         BuildEvent event = new BuildEvent(this);
         Iterator iter = listeners.iterator();
         while (iter.hasNext()) {
@@ -1889,7 +1899,7 @@
      *
      * @since Ant 1.6.2
      */
-    public synchronized void fireSubBuildFinished(Throwable exception) {
+    public void fireSubBuildFinished(Throwable exception) {
         BuildEvent event = new BuildEvent(this);
         event.setException(exception);
         Iterator iter = listeners.iterator();
@@ -1908,7 +1918,7 @@
      * @param target The target which is starting to build.
      *               Must not be <code>null</code>.
      */
-    protected synchronized void fireTargetStarted(Target target) {
+    protected void fireTargetStarted(Target target) {
         BuildEvent event = new BuildEvent(target);
         Iterator iter = listeners.iterator();
         while (iter.hasNext()) {
@@ -1927,8 +1937,7 @@
      *                  failure. May be <code>null</code>, indicating
      *                  a successful build.
      */
-    protected synchronized void fireTargetFinished(Target target,
-                                                   Throwable exception) {
+    protected void fireTargetFinished(Target target, Throwable exception) {
         BuildEvent event = new BuildEvent(target);
         event.setException(exception);
         Iterator iter = listeners.iterator();
@@ -1945,7 +1954,7 @@
      * @param task The target which is starting to execute.
      *               Must not be <code>null</code>.
      */
-    protected synchronized void fireTaskStarted(Task task) {
+    protected void fireTaskStarted(Task task) {
         // register this as the current task on the current thread.
         registerThreadTask(Thread.currentThread(), task);
         BuildEvent event = new BuildEvent(task);
@@ -1966,7 +1975,7 @@
      *                  failure. May be <code>null</code>, indicating
      *                  a successful build.
      */
-    protected synchronized void fireTaskFinished(Task task, Throwable exception) {
+    protected void fireTaskFinished(Task task, Throwable exception) {
         registerThreadTask(Thread.currentThread(), null);
         System.out.flush();
         System.err.flush();
@@ -1990,9 +1999,8 @@
      * @param message  The message to send. Should not be <code>null</code>.
      * @param priority The priority of the message.
      */
-    private synchronized void fireMessageLoggedEvent(BuildEvent event,
-                                                     String message,
-                                                     int priority) {
+    private void fireMessageLoggedEvent(BuildEvent event, String message,
+                                        int priority) {
 
         if (message.endsWith(StringUtils.LINE_SEP)) {
             int endIndex = message.length() - StringUtils.LINE_SEP.length();
@@ -2039,8 +2047,8 @@
      * @param message  The message to send. Should not be <code>null</code>.
      * @param priority The priority of the message.
      */
-    protected synchronized void fireMessageLogged(Project project, String message,
-                                                  int priority) {
+    protected void fireMessageLogged(Project project, String message,
+                                     int priority) {
         BuildEvent event = new BuildEvent(project);
         fireMessageLoggedEvent(event, message, priority);
     }
@@ -2054,8 +2062,8 @@
      * @param message  The message to send. Should not be <code>null</code>.
      * @param priority The priority of the message.
      */
-    protected synchronized void fireMessageLogged(Target target, String message,
-                                                  int priority) {
+    protected void fireMessageLogged(Target target, String message,
+                                     int priority) {
         BuildEvent event = new BuildEvent(target);
         fireMessageLoggedEvent(event, message, priority);
     }
@@ -2069,8 +2077,7 @@
      * @param message  The message to send. Should not be <code>null</code>.
      * @param priority The priority of the message.
      */
-    protected synchronized void fireMessageLogged(Task task, String message,
-                                                  int priority) {
+    protected void fireMessageLogged(Task task, String message, int priority) {
         BuildEvent event = new BuildEvent(task);
         fireMessageLoggedEvent(event, message, priority);
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message