diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java index 1d757bdcc..7a9766409 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java @@ -147,11 +147,21 @@ public class ExecuteWatchdog implements Runnable { wait(until - now); } catch (InterruptedException e) {} } - // if we are here, either someone stopped the watchdog or we are on timeout - // if watch is true, it means its a timeout - if (watch) { - killedProcess = true; - process.destroy(); + + // if we are here, either someone stopped the watchdog, + // we are on timeout and the process must be killed, or + // we are on timeout and the process has already stopped. + try { + // We must check if the process was not stopped + // before being here + process.exitValue(); + } catch (IllegalThreadStateException e){ + // the process is not terminated, if this is really + // a timeout and not a manual stop then kill it. + if (watch){ + killedProcess = true; + process.destroy(); + } } } catch(Exception e) { caught = e;