From 54b827ff4f14f4290b0673b4afcec3a2579889a8 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Mon, 15 Mar 2004 11:23:48 +0000
Subject: [PATCH] Don't swallow the stack trace if a Java program throws an
exception.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276233 13f79535-47bb-0310-9956-ffa450edef68
---
WHATSNEW | 3 +++
docs/faq.html | 18 ++++++++++++++++++
.../org/apache/tools/ant/taskdefs/Java.java | 16 ++++++++++++++--
xdocs/faq.xml | 15 +++++++++++++++
4 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index 5cf33cace..e02742e70 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -84,6 +84,9 @@ Fixed bugs:
* NPE when running commons listener. Bugzilla Report 27373.
+* swallowed the stack trace of exceptions thrown by the
+ executed program if run in the same VM.
+
Other changes:
--------------
diff --git a/docs/faq.html b/docs/faq.html
index 7a5d2f2ed..ce4ab7f56 100644
--- a/docs/faq.html
+++ b/docs/faq.html
@@ -341,6 +341,12 @@
Why do my custom task containers see Unknown Elements in Ant 1.6
- they worked in Ant 1.5?
+
+
+
+ The program I run via <java> throws an exception but I
+ can't seem to get the full stack trace.
+
@@ -1593,6 +1599,18 @@ mv /tmp/foo $ANT_HOME/bin/antRun
This approach should work for ant1.5 and ant1.6.
+
+
+
+ The program I run via <java> throws an exception but I
+ can't seem to get the full stack trace.
+
+
+ This is a know bug that has been fixed after the release of
+ Ant 1.6.1.
+ As a workaround, run your <java> task with
+ fork="true"
and Ant will display the full
+ trace.
diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java
index ae361a69a..ae2553abe 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Java.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Java.java
@@ -19,6 +19,8 @@ package org.apache.tools.ant.taskdefs;
import java.io.File;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ExitException;
@@ -169,14 +171,14 @@ public class Java extends Task {
if (failOnError) {
throw e;
} else {
- log(e.getMessage(), Project.MSG_ERR);
+ log(e);
return 0;
}
} catch (Throwable t) {
if (failOnError) {
throw new BuildException(t);
} else {
- log(t.getMessage(), Project.MSG_ERR);
+ log(t);
return 0;
}
}
@@ -792,4 +794,14 @@ public class Java extends Task {
return new ExecuteWatchdog(timeout.longValue());
}
+ /**
+ * @since 1.6.2
+ */
+ private void log(Throwable t) {
+ StringWriter sw = new StringWriter();
+ PrintWriter w = new PrintWriter(sw);
+ t.printStackTrace(w);
+ w.close();
+ log(sw.toString(), Project.MSG_ERR);
+ }
}
diff --git a/xdocs/faq.xml b/xdocs/faq.xml
index b3cc58afb..8f9c0885a 100644
--- a/xdocs/faq.xml
+++ b/xdocs/faq.xml
@@ -1409,6 +1409,21 @@ mv /tmp/foo $ANT_HOME/bin/antRun
+
+
+
+ The program I run via <java> throws an exception but I
+ can't seem to get the full stack trace.
+
+
+ This is a know bug that has been fixed after the release of
+ Ant 1.6.1.
+
+ As a workaround, run your <java> task with
+ fork="true"
and Ant will display the full
+ trace.
+
+