https://issues.apache.org/bugzilla/show_bug.cgi?id=44544





--- Comment #2 from Eric Bloch <[EMAIL PROTECTED]>  2008-03-06 03:04:56 PST ---
Here ya go!

--

<project name="bug-xxxxx" default="bug" >
    <target name="bug">
        <java classname="ReaderAndWriter" >
            <classpath>
                <pathelement path="${basedir}"/>
            </classpath>
        </java>
    </target>
</project>

and src code for ReaderAndWriter below

--
import java.io.*;

class Reader extends Thread {
    public void run() {
        try {
            while(true) {
                int x = System.in.read();
                if (x == -1) {
                    break;
                }
            }
        } catch (IOException ioe) {
            return;
        }
    }
}

public class ReaderAndWriter {
    static public void main(String[] args) {
        Reader reader = new Reader();
        reader.start();

        for(int i = 1; i < 10; i++) {
            System.out.println("I love ant.");
        }
    }
}

--


Run ant and notice the hangs.  Everytime you hit carriage return
you can see some output go by.  Expected results is you'd see your 10 lines of
output get printed and then ant should exit.  As I read the code in Redirector,
it needs some love wrt the aggressive use of synchronization.  There's no need,
afa I can tell for writes to be locked out while you're reading.




I fixed by workaround to be more striaghtfwd too.  Here it is now:

/*
 * CONFIDENTIAL COMPUTER CODE AND INFORMATION
 * COPYRIGHT (C) 2004-2008 TENEO SYSTEMS, INC. ALL RIGHTS RESERVED.
 * REPRODUCTION BY ANY MEANS EXPRESSLY FORBIDDEN WITHOUT THE WRITTEN
 * PERMISSION OF THE OWNER.
 */
package com.teneo.esa.ant;

import java.io.InputStream;
import java.io.IOException;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.Project;

/**
 * Workaround for Ant bug: 44544; 
 * See https://issues.apache.org/bugzilla/show_bug.cgi?id=44544
 *
 * @author bloch
 */
public class JavaWithWorkaround extends Java {

    private InputStream _s;

    /**
     * [EMAIL PROTECTED]
     */
    @Override protected void setupRedirector() {
    }

    /**
     * [EMAIL PROTECTED]
     */
    @Override protected void handleOutput(String output) {
        log(output, Project.MSG_INFO);
    }

    /**
     * [EMAIL PROTECTED]
     */
    @Override protected void handleFlush(String output) {
        handleOutput(output);
    }

    /**
     * [EMAIL PROTECTED]
     */
    @Override public int handleInput(byte[] buffer, int offset, int length)
        throws IOException {
        return getProject().defaultInput(buffer, offset, length);
    }
}


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Reply via email to