Just a minor suggested patch--it seems cleaner for BuildException to
automatically print its nested exception, rather than someone else doing
it. More consistent with various wrapper exception classes in the JRE
too.

Also in some JDK "non-public release" (sigh) BuildException could
actually get some help:
http://developer.java.sun.com/developer/bugParade/bugs/4209652.html

-Jesse

-- 
Jesse Glick   <mailto:[EMAIL PROTECTED]>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR
Index: src/main/org/apache/tools/ant/BuildException.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/BuildException.java,v
retrieving revision 1.9
diff -u -r1.9 BuildException.java
--- src/main/org/apache/tools/ant/BuildException.java   2001/01/03 14:18:26     
1.9
+++ src/main/org/apache/tools/ant/BuildException.java   2001/01/25 11:42:50
@@ -53,6 +53,9 @@
  */
 package org.apache.tools.ant;
 
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
 /**
  * Signals an error condition during a build.
  *
@@ -161,5 +164,26 @@
      */
     public Location getLocation() {
         return location;
+    }
+
+    // Override stack trace methods to show original cause:
+    public void printStackTrace() {
+        printStackTrace(System.err);
+    }
+    public void printStackTrace(PrintStream ps) {
+        synchronized (ps) {
+            ps.println(this);
+            if (cause != null) {
+                cause.printStackTrace(ps);
+            }
+        }
+    }
+    public void printStackTrace(PrintWriter pw) {
+        synchronized (pw) {
+            pw.println(this);
+            if (cause != null) {
+                cause.printStackTrace(pw);
+            }
+        }
     }
 }
Index: src/main/org/apache/tools/ant/DefaultLogger.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/DefaultLogger.java,v
retrieving revision 1.13
diff -u -r1.13 DefaultLogger.java
--- src/main/org/apache/tools/ant/DefaultLogger.java    2001/01/11 12:13:02     
1.13
+++ src/main/org/apache/tools/ant/DefaultLogger.java    2001/01/25 11:42:50
@@ -137,18 +137,7 @@
         }
         else {
             err.println(lSep + "BUILD FAILED" + lSep);
-
-            if (error instanceof BuildException) {
-                err.println(error.toString());
-
-                Throwable nested = ((BuildException)error).getException();
-                if (nested != null) {
-                    nested.printStackTrace(err);
-                }
-            }
-            else {
-                error.printStackTrace(err);
-            }
+            error.printStackTrace(err);
         }
 
         out.println(lSep + "Total time: " + 
formatTime(System.currentTimeMillis() - startTime));

Reply via email to