ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mr Pink <>
Subject Re: AW: custom task calls classes with logging = NPE
Date Mon, 30 Aug 2004 12:17:39 GMT
Hi Jan,

I finally figured out was was wrong. Yes, it is possible to use System.out from within an
ant task
but I had introduced a seperate problem into my code.

Perhaps you are familiar with the tutorial on writing your own task? I followed it and then
my development on that. In the tutorial, the first example puts this method in the task:

    private Project project;

    public void setProject(Project proj) {
        project = proj;

It disappears in the next version of the example (with no explanation, or maybe I just misssed
that bit) and if you leave it in like that (as I did), you're gonna start having NPE coming
your ears.

Anyway, once I realized what was happening I pulled the code out and everything was working
I had already removed all refernces to System.out and loggers so it hadn't clicked with me
they might actually start working again. After reading your reply I tested it out and it's

Thanks for you help
Mr Pink

--- wrote:

> > I understand that Ant is closing the System.out and 
> > System.err streams and I can kinda appreciate
> > why it's doing that, but it's proving to be a problem for me, 
> > since my task calls various classes
> > that are not aware of ant and those classes use logging and 
> > possibly even direct references to to
> > System.out causing my task to fail with a NullPointerException.
> Im not aware that Ant _closes_ these streams ...
> Ant uses its own streams:
> System.setIn(new DemuxInputStream(project));
> System.setOut(new PrintStream(new DemuxOutputStream(project,
> false)));
> System.setErr(new PrintStream(new DemuxOutputStream(project,
> true)));
> DemuxOutputStream:
> "Logs content written by a thread and forwards the buffers onto the
> project object which will forward the content to the appropriate task."
> > In short, I'd like to know how one deals with that.
> The usual way for logging is invoking the tasks log() method ...
> For your external classes: <java> supports a <redirector>. Maybe you can
> something
> with that (its early in the morning - maybe thats not the best idea...)
> Jan

Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message