Author: bodewig
Date: Tue Feb 9 13:58:27 2010
New Revision: 908035
URL: http://svn.apache.org/viewvc?rev=908035&view=rev
Log:
Avoid ConcurrentModificationException when iteratong over life-maps. PR 48310
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/Project.java
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=908035&r1=908034&r2=908035&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Feb 9 13:58:27 2010
@@ -7,9 +7,18 @@
Fixed bugs:
-----------
+ * Tasks that iterate over task or type definitions, references or
+ targets now iterate over copies instead of the live maps to avoid
+ ConcurrentModificationExceptions if another thread changes the
+ maps.
+ Bugzilla Report 48310.
+
Other changes:
--------------
+ * Project provides new get methods that return copies instead of the
+ live maps of task and type definitions, references and targets.
+
Changes from Ant 1.8.0RC1 TO Ant 1.8.0
======================================
Modified: ant/core/trunk/src/main/org/apache/tools/ant/Project.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Project.java?rev=908035&r1=908034&r2=908035&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 Tue Feb 9
13:58:27 2010
@@ -425,10 +425,10 @@
}
/**
- * Return a copy of the list of build listeners for the project.
- *
- * @return a list of build listeners for the project
- */
+ * Return a copy of the list of build listeners for the project.
+ *
+ * @return a list of build listeners for the project
+ */
public Vector getBuildListeners() {
synchronized (listenersLock) {
Vector r = new Vector(listeners.length);
@@ -1025,6 +1025,19 @@
}
/**
+ * Return the current task definition map. The returned map is a
+ * copy of the "live" definitions.
+ *
+ * @return a map of from task name to implementing class
+ * (String to Class).
+ *
+ * @since Ant 1.8.1
+ */
+ public Map getCopyOfTaskDefinitions() {
+ return new HashMap(getTaskDefinitions());
+ }
+
+ /**
* Add a new datatype definition.
* Attempting to override an existing definition with an
* equivalent one (i.e. with the same classname) results in
@@ -1054,6 +1067,19 @@
}
/**
+ * Return the current datatype definition map. The returned
+ * map is a copy pf the "live" definitions.
+ *
+ * @return a map of from datatype name to implementing class
+ * (String to Class).
+ *
+ * @since Ant 1.8.1
+ */
+ public Map getCopyOfDataTypeDefinitions() {
+ return new HashMap(getDataTypeDefinitions());
+ }
+
+ /**
* Add a <em>new</em> target to the project.
*
* @param target The target to be added to the project.
@@ -1124,6 +1150,16 @@
}
/**
+ * Return the map of targets. The returned map
+ * is a copy of the "live" targets.
+ * @return a map from name to target (String to Target).
+ * @since Ant 1.8.1
+ */
+ public Map getCopyOfTargets() {
+ return new HashMap(targets);
+ }
+
+ /**
* Create a new instance of a task, adding it to a list of
* created tasks for later invalidation. This causes all tasks
* to be remembered until the containing project is removed
@@ -1971,6 +2007,19 @@
}
/**
+ * Return a map of the references in the project (String to
+ * Object). The returned hashtable is a copy of the
+ * "live" references.
+ *
+ * @return a map of the references in the project (String to Object).
+ *
+ * @since Ant 1.8.1
+ */
+ public Map getCopyOfReferences() {
+ return new HashMap(references);
+ }
+
+ /**
* Look up a reference by its key (ID).
*
* @param key The key for the desired reference.
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java?rev=908035&r1=908034&r2=908035&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java Tue
Feb 9 13:58:27 2010
@@ -27,6 +27,7 @@
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.IntrospectionHelper;
@@ -95,22 +96,24 @@
}
printer.printHead(out, getProject(),
- getProject().getTaskDefinitions(),
- getProject().getDataTypeDefinitions());
+ new Hashtable(getProject().getTaskDefinitions()),
+ new
Hashtable(getProject().getDataTypeDefinitions()));
printer.printTargetDecl(out);
- Enumeration dataTypes =
getProject().getDataTypeDefinitions().keys();
- while (dataTypes.hasMoreElements()) {
- String typeName = (String) dataTypes.nextElement();
+ Iterator dataTypes = getProject().getCopyOfDataTypeDefinitions()
+ .keySet().iterator();
+ while (dataTypes.hasNext()) {
+ String typeName = (String) dataTypes.next();
printer.printElementDecl(
out, getProject(), typeName,
(Class)
getProject().getDataTypeDefinitions().get(typeName));
}
- Enumeration tasks = getProject().getTaskDefinitions().keys();
- while (tasks.hasMoreElements()) {
- String tName = (String) tasks.nextElement();
+ Iterator tasks = getProject().getCopyOfTaskDefinitions().keySet()
+ .iterator();
+ while (tasks.hasNext()) {
+ String tName = (String) tasks.next();
printer.printElementDecl(out, getProject(), tName,
(Class)
getProject().getTaskDefinitions().get(tName));
}
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java?rev=908035&r1=908034&r2=908035&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java Tue
Feb 9 13:58:27 2010
@@ -306,8 +306,8 @@
project = component.getProject();
addBeans(project.getProperties());
addBeans(project.getUserProperties());
- addBeans(project.getTargets());
- addBeans(project.getReferences());
+ addBeans(project.getCopyOfTargets());
+ addBeans(project.getCopyOfReferences());
addBean("project", project);
addBean("self", component);
}