You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2007/12/22 02:22:29 UTC

svn commit: r606371 - in /commons/proper/io/trunk/src: java/org/apache/commons/io/CausedIOException.java test/org/apache/commons/io/CausedIOExceptionTestCase.java

Author: ggregory
Date: Fri Dec 21 17:22:29 2007
New Revision: 606371

URL: http://svn.apache.org/viewvc?rev=606371&view=rev
Log:
A second cut on [IO-148]: IOException with constructors which take a cause. New Throwable constructor. New Javadoc.

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/CausedIOException.java
    commons/proper/io/trunk/src/test/org/apache/commons/io/CausedIOExceptionTestCase.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/CausedIOException.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/CausedIOException.java?rev=606371&r1=606370&r2=606371&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/CausedIOException.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/CausedIOException.java Fri Dec 21 17:22:29 2007
@@ -20,11 +20,13 @@
 import java.io.IOException;
 
 /**
- * Subclasses IOException with the {@link Throwable} constructor was missing before Java 6.
+ * Subclasses IOException with the {@link Throwable} constructors missing before Java 6. If you are using Java 6,
+ * consider this class deprecated and use {@link IOException}.
  * 
  * @see <a href="mailto:commons-user@jakarta.apache.org">Apache Commons Users List</a>
  * @author <a href="http://commons.apache.org/io/">Apache Commons IO</a>
  * @version $Id: $
+ * @since 1.4
  */
 public class CausedIOException extends IOException {
 
@@ -34,18 +36,37 @@
     private static final long serialVersionUID = 1L;
 
     /**
-     * Creates an instance with the given message and cause.
+     * Constructs a new instance with the specified detail message and cause.
      * <p>
-     * This constructor was not added in the underlying {@link IOException} class until Java 6. This is a convenience
-     * method which uses the {@link #initCause(Throwable)} method to set the root cause.
+     * Note that the detail message associated with <code>cause</code> is <i>not</i> automatically incorporated in
+     * this throwable's detail message.
+     * </p>
      * 
      * @param message
-     *            exception message
+     *            the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
      * @param cause
-     *            root cause
+     *            the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <code>null</code>
+     *            value is permitted, and indicates that the cause is nonexistent or unknown.)
      */
     public CausedIOException(String message, Throwable cause) {
         super(message);
+        this.initCause(cause);
+    }
+
+    /**
+     * Constructs a new exception with the specified cause and a detail message.
+     * <p>
+     * The message is <code>(cause==null ? null : cause.toString())</code> (which typically contains the class and
+     * detail message of <code>cause</code>). This constructor is useful for exceptions that are little more than
+     * wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}).
+     * </p>
+     * 
+     * @param cause
+     *            the cause (which is saved for later retrieval by the {@link #getCause()} method). (A <code>null</code>
+     *            value is permitted, and indicates that the cause is nonexistent or unknown.)
+     */
+    public CausedIOException(Throwable cause) {
+        super(cause == null ? null : cause.toString());
         this.initCause(cause);
     }
 

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/CausedIOExceptionTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/CausedIOExceptionTestCase.java?rev=606371&r1=606370&r2=606371&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/CausedIOExceptionTestCase.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/CausedIOExceptionTestCase.java Fri Dec 21 17:22:29 2007
@@ -33,8 +33,21 @@
     public void testIOExceptionStringThrowable() {
         Throwable cause = new IllegalArgumentException("cause");
         CausedIOException exception = new CausedIOException("message", cause);
-        assertEquals("message", exception.getMessage());
-        assertEquals(cause, exception.getCause());
-        assertSame(cause, exception.getCause());
+        this.validate(exception, cause, "message");
+    }
+
+    /**
+     * Tests the {@link CausedIOException#CausedIOException(Throwable)} constructor.
+     */
+    public void testIOExceptionThrowable() {
+        Throwable cause = new IllegalArgumentException("cause");
+        CausedIOException exception = new CausedIOException(cause);
+        this.validate(exception, cause, "java.lang.IllegalArgumentException: cause");
+    }
+
+    void validate(Throwable throwable, Throwable expectedCause, String expectedMessage) {
+        assertEquals(expectedMessage, throwable.getMessage());
+        assertEquals(expectedCause, throwable.getCause());
+        assertSame(expectedCause, throwable.getCause());
     }
 }