From d3b91deae0ef14621eda83711e6afebd50deb810 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Mon, 24 Oct 2005 22:14:53 +0000 Subject: [PATCH] Revert previous change; apparently I am unhinged because I can't see how it's happening but I'm getting ConcurrentModificationExceptions willy-nilly. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@328166 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/Project.java | 51 ++++++++++++---------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 0a8d07c4d..c406e7b0e 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -324,12 +324,18 @@ public class Project { * be notified of build events for this project. * * @param listener The listener to add to the list. - * Ignored if null. + * Must not be null. */ 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 @@ public class Project { * Should not be null. */ 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 @@ public class Project { * Send a "build started" 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 @@ public class Project { * failure. May be null, 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 @@ public class Project { * * @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 @@ public class Project { * * @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 @@ public class Project { * @param target The target which is starting to build. * Must not be null. */ - 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 @@ public class Project { * failure. May be null, 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 @@ public class Project { * @param task The target which is starting to execute. * Must not be null. */ - 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 @@ public class Project { * failure. May be null, 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 @@ public class Project { * @param message The message to send. Should not be null. * @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 @@ public class Project { * @param message The message to send. Should not be null. * @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 @@ public class Project { * @param message The message to send. Should not be null. * @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 @@ public class Project { * @param message The message to send. Should not be null. * @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); }