Return-Path: Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Delivered-To: mailing list dev@ant.apache.org Received: (qmail 16258 invoked by uid 500); 17 Feb 2003 14:12:12 -0000 Received: (qmail 16255 invoked from network); 17 Feb 2003 14:12:11 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 17 Feb 2003 14:12:11 -0000 Received: (qmail 42279 invoked by uid 1142); 17 Feb 2003 14:12:11 -0000 Date: 17 Feb 2003 14:12:11 -0000 Message-ID: <20030217141211.42278.qmail@icarus.apache.org> From: conor@apache.org To: ant-cvs@apache.org Subject: cvs commit: ant/src/main/org/apache/tools/ant Project.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 @@

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.

+

Note: 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. +

+

Source code integration

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; } }