You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@apache.org on 2003/02/17 15:12:11 UTC
cvs commit: ant/src/main/org/apache/tools/ant Project.java
conor 2003/02/17 06:12:10
Modified: docs/manual develop.html
src/main/org/apache/tools/ant Project.java
Log:
Detect listener attempts to access System.out/System.err and
terminate with a build exception before entering an infinte loop
PR: 14863
Revision Changes Path
1.13 +8 -0 ant/docs/manual/develop.html
Index: develop.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/develop.html,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -u -r1.12 -r1.13
--- develop.html 24 Jan 2003 08:55:05 -0000 1.12
+++ develop.html 17 Feb 2003 14:12:10 -0000 1.13
@@ -336,6 +336,14 @@
<p>will run Ant with a listener that generates an XML representation of the build progress. This
listener is included with Ant, as is the default listener, which generates the logging to standard output.</p>
+<p><b>Note: </b>A listener must not access System.out and System.err directly since ouput on
+these streams is redirected by Ant's core to the build event system. Accessing these
+streams can cause an infinite loop in Ant. Depending on the version of Ant, this will
+either cause the build to terminate or the Java VM to run out of Stack space. A logger, also, may
+not access System.out and System.err directly. It must use the streams with which it has
+been configured.
+</p>
+
<hr>
<h2><a name="integration">Source code integration</a></h2>
1.132 +18 -4 ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -w -u -r1.131 -r1.132
--- Project.java 10 Feb 2003 14:13:30 -0000 1.131
+++ Project.java 17 Feb 2003 14:12:10 -0000 1.132
@@ -254,6 +254,11 @@
private FileUtils fileUtils;
/**
+ * Flag which catches Listeners which try to use System.out or System.err
+ */
+ private boolean loggingMessage = false;
+
+ /**
* Creates a new Ant project.
*/
public Project() {
@@ -2055,9 +2060,18 @@
int priority) {
event.setMessage(message, priority);
Vector listeners = getBuildListeners();
+ synchronized(this) {
+ if (loggingMessage) {
+ throw new BuildException("Listener attempted to access "
+ + (priority == MSG_ERR ? "System.err" : "System.out")
+ + " - infinite loop terminated");
+ }
+ loggingMessage = true;
for (int i = 0; i < listeners.size(); i++) {
BuildListener listener = (BuildListener) listeners.elementAt(i);
listener.messageLogged(event);
+ }
+ loggingMessage = false;
}
}