Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C529111E5E for ; Sat, 12 Apr 2014 12:02:29 +0000 (UTC) Received: (qmail 55781 invoked by uid 500); 12 Apr 2014 12:02:28 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 55473 invoked by uid 500); 12 Apr 2014 12:02:24 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 55466 invoked by uid 99); 12 Apr 2014 12:02:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 12 Apr 2014 12:02:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 12 Apr 2014 12:02:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D2EA6238889B; Sat, 12 Apr 2014 12:02:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1586853 - /commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java Date: Sat, 12 Apr 2014 12:02:01 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140412120201.D2EA6238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebb Date: Sat Apr 12 12:02:01 2014 New Revision: 1586853 URL: http://svn.apache.org/r1586853 Log: Start to fix up closeQuietly Javadoc Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java?rev=1586853&r1=1586852&r2=1586853&view=diff ============================================================================== --- commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java (original) +++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java Sat Apr 12 12:02:01 2014 @@ -331,8 +331,16 @@ public class IOUtils { /** * Closes a Closeable unconditionally. *

- * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored. This is typically used in - * finally blocks. + * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored. + *

+ * This is typically used in finally blocks to ensure that the closeable is closed + * even if an Exception was thrown before the normal close statement was reached. + *
+ * It should not be used to replace the close statement(s) + * which should be present for the non-exceptional case. + *
+ * It is only intended to simplify tidying up where normal processing has already failed + * and reporting close failure as well is not necessary or useful. *

* Example code: * @@ -340,29 +348,29 @@ public class IOUtils { * Closeable closeable = null; * try { * closeable = new FileReader("foo.txt"); - * // process closeable - * closeable.close(); + * // processing using the closeable; may throw an Exception + * closeable.close(); // Normal close - exceptions not ignored * } catch (Exception e) { * // error handling * } finally { - * IOUtils.closeQuietly(closeable); + * IOUtils.closeQuietly(closeable); // In case normal close was skipped due to Exception * } * * * Closing all streams: - * + *
TODO - fix this example, it is wrong; ought not to ignore Exceptions here *

      * try {
      *     return IOUtils.copy(inputStream, outputStream);
      * } finally {
-     *     IOUtils.closeQuietly(inputStream);
-     *     IOUtils.closeQuietly(outputStream);
+     *     IOUtils.closeQuietly(inputStream, outputStream);
      * }
      * 
* * @param closeables * the objects to close, may be null or already closed * @since 2.5 + * @see #closeQuietly(Closeable) */ public static void closeQuietly(final Closeable... closeables) { if (closeables == null) {