ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r808169 - in /ant/core/trunk/src: main/org/apache/tools/ant/ main/org/apache/tools/ant/taskdefs/ tests/junit/org/apache/tools/ant/ tests/junit/org/apache/tools/ant/taskdefs/
Date Wed, 26 Aug 2009 20:19:20 GMT
Author: jglick
Date: Wed Aug 26 20:19:20 2009
New Revision: 808169

URL: http://svn.apache.org/viewvc?rev=808169&view=rev
Log:
Taking advantage of Throwable.cause.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/BuildException.java
    ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/BuildException.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/BuildException.java?rev=808169&r1=808168&r2=808169&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/BuildException.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/BuildException.java Wed Aug 26 20:19:20 2009
@@ -17,9 +17,6 @@
  */
 package org.apache.tools.ant;
 
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
 /**
  * Signals an error condition during a build
  */
@@ -27,9 +24,6 @@
 
     private static final long serialVersionUID = -5419014565354664240L;
 
-    /** Exception that might have caused this one. */
-    private Throwable cause;
-
     /** Location in the build file where the exception occurred */
     private Location location = Location.UNKNOWN_LOCATION;
 
@@ -61,7 +55,7 @@
      */
     public BuildException(String message, Throwable cause) {
         super(message);
-        this.cause = cause;
+        initCause(cause);
     }
 
     /**
@@ -87,8 +81,7 @@
      *              Should not be <code>null</code>.
      */
     public BuildException(Throwable cause) {
-        super(cause.toString());
-        this.cause = cause;
+        super(cause);
     }
 
     /**
@@ -124,19 +117,10 @@
      *
      * @return the nested exception, or <code>null</code> if no
      *         exception is associated with this one
+     * @deprecated Use {@link #getCause} instead.
      */
     public Throwable getException() {
-        return cause;
-    }
-
-    /**
-     * Returns the nested exception, if any.
-     *
-     * @return the nested exception, or <code>null</code> if no
-     *         exception is associated with this one
-     */
-    public Throwable getCause() {
-        return getException();
+        return getCause();
     }
 
     /**
@@ -167,45 +151,4 @@
         return location;
     }
 
-    /**
-     * Prints the stack trace for this exception and any
-     * nested exception to <code>System.err</code>.
-     */
-    public void printStackTrace() {
-        printStackTrace(System.err);
-    }
-
-    /**
-     * Prints the stack trace of this exception and any nested
-     * exception to the specified PrintStream.
-     *
-     * @param ps The PrintStream to print the stack trace to.
-     *           Must not be <code>null</code>.
-     */
-    public void printStackTrace(PrintStream ps) {
-        synchronized (ps) {
-            super.printStackTrace(ps);
-            if (cause != null) {
-                ps.println("--- Nested Exception ---");
-                cause.printStackTrace(ps);
-            }
-        }
-    }
-
-    /**
-     * Prints the stack trace of this exception and any nested
-     * exception to the specified PrintWriter.
-     *
-     * @param pw The PrintWriter to print the stack trace to.
-     *           Must not be <code>null</code>.
-     */
-    public void printStackTrace(PrintWriter pw) {
-        synchronized (pw) {
-            super.printStackTrace(pw);
-            if (cause != null) {
-                pw.println("--- Nested Exception ---");
-                cause.printStackTrace(pw);
-            }
-        }
-    }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java?rev=808169&r1=808168&r2=808169&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/DefaultLogger.java Wed Aug 26 20:19:20 2009
@@ -132,7 +132,7 @@
 
     static void throwableMessage(StringBuffer m, Throwable error, boolean verbose) {
         while (error instanceof BuildException) { // #43398
-            Throwable cause = ((BuildException) error).getCause();
+            Throwable cause = error.getCause();
             if (cause == null) {
                 break;
             }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java?rev=808169&r1=808168&r2=808169&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java Wed Aug 26
20:19:20 2009
@@ -368,7 +368,7 @@
             if (failOnError) {
                 throw(e);
             }
-            Throwable t = e.getException();
+            Throwable t = e.getCause();
             if (t == null) {
                 t = e;
             }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java?rev=808169&r1=808168&r2=808169&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java Wed Aug
26 20:19:20 2009
@@ -67,7 +67,7 @@
             ih.addText(p, this, "test2");
             fail("test2 shouldn\'t be equal to test");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
 
         ih = IntrospectionHelper.getHelper(String.class);
@@ -166,14 +166,14 @@
             ih.createElement(p, this, "fourteen");
             fail("fourteen throws NullPointerException");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof NullPointerException);
+            assertTrue(be.getCause() instanceof NullPointerException);
         }
 
         try {
             ih.createElement(p, this, "fourteen");
             fail("fifteen throws NullPointerException");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof NullPointerException);
+            assertTrue(be.getCause() instanceof NullPointerException);
         }
     }
 
@@ -322,97 +322,97 @@
             ih.setAttribute(p, this, "seven", "3");
             fail("2 shouldn't be equals to three");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "eight", "2");
         try {
             ih.setAttribute(p, this, "eight", "3");
             fail("2 shouldn't be equals to three - as int");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "nine", "2");
         try {
             ih.setAttribute(p, this, "nine", "3");
             fail("2 shouldn't be equals to three - as Integer");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "ten", "2");
         try {
             ih.setAttribute(p, this, "ten", "3");
             fail(projectBasedir+"2 shouldn't be equals to "+projectBasedir+"3");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "eleven", "2");
         try {
             ih.setAttribute(p, this, "eleven", "on");
             fail("on shouldn't be false");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "twelve", "2");
         try {
             ih.setAttribute(p, this, "twelve", "on");
             fail("on shouldn't be false");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project");
         try {
             ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.ProjectHelper");
             fail("org.apache.tools.ant.Project shouldn't be equal to org.apache.tools.ant.ProjectHelper");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         try {
             ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project2");
             fail("org.apache.tools.ant.Project2 doesn't exist");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof ClassNotFoundException);
+            assertTrue(be.getCause() instanceof ClassNotFoundException);
         }
         ih.setAttribute(p, this, "fourteen", "2");
         try {
             ih.setAttribute(p, this, "fourteen", "on");
             fail("2 shouldn't be equals to three - as StringBuffer");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "fifteen", "abcd");
         try {
             ih.setAttribute(p, this, "fifteen", "on");
             fail("o shouldn't be equal to a");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "sixteen", "abcd");
         try {
             ih.setAttribute(p, this, "sixteen", "on");
             fail("o shouldn't be equal to a");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "seventeen", "17");
         try {
             ih.setAttribute(p, this, "seventeen", "3");
             fail("17 shouldn't be equals to three");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "eightteen", "18");
         try {
             ih.setAttribute(p, this, "eightteen", "3");
             fail("18 shouldn't be equals to three");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
         ih.setAttribute(p, this, "nineteen", "19");
         try {
             ih.setAttribute(p, this, "nineteen", "3");
             fail("19 shouldn't be equals to three");
         } catch (BuildException be) {
-            assertTrue(be.getException() instanceof AssertionFailedError);
+            assertTrue(be.getCause() instanceof AssertionFailedError);
         }
     }
 

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java?rev=808169&r1=808168&r2=808169&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java Wed Aug
26 20:19:20 2009
@@ -70,7 +70,7 @@
         try {
             sql.execute();
         } catch (BuildException e){
-            assertTrue(e.getException().getMessage().indexOf("No suitable Driver") != -1);
+            assertTrue(e.getCause().getMessage().indexOf("No suitable Driver") != -1);
         }
         assertTrue(SQLExec.getLoaderMap().containsKey(NULL_DRIVER));
         assertSame(sql.getLoader(), JDBCTask.getLoaderMap().get(NULL_DRIVER));
@@ -83,7 +83,7 @@
         try {
             sql.execute();
         } catch (BuildException e){
-            assertTrue(e.getException().getMessage().indexOf("No suitable Driver") != -1);
+            assertTrue(e.getCause().getMessage().indexOf("No suitable Driver") != -1);
         }
         assertTrue(JDBCTask.getLoaderMap().containsKey(NULL_DRIVER));
         assertSame(sql.getLoader(), JDBCTask.getLoaderMap().get(NULL_DRIVER));



Mime
View raw message