ppkarwasz commented on code in PR #818:
URL: https://github.com/apache/commons-io/pull/818#discussion_r2614025351
##########
src/main/java/org/apache/commons/io/IOUtils.java:
##########
@@ -824,7 +824,40 @@ private static void closeQ(final Closeable closeable) {
* @see Throwable#addSuppressed(Throwable)
*/
public static void closeQuietly(final Closeable closeable) {
- closeQuietly(closeable, null);
+ closeQuietly(closeable, (Consumer<Exception>) null);
+ }
+
+ /**
+ * Closes a {@link Closeable} unconditionally and adds any exception
thrown by the {@code close()} to the given Throwable.
+ *
+ * <p>
+ * For example:
+ * </p>
+ *
+ * <pre>
+ * Closeable closeable = ...;
+ * try {
+ * // process closeable
+ * closeable.close();
+ * } catch (Exception e) {
+ * // error handling
+ * throw IOUtils.closeQuietly(closeable, e);
+ * }
+ * </pre>
+ * <p>
+ * Also consider using a try-with-resources statement where appropriate.
+ * </p>
+ *
+ * @param <T> The Throwable type.
+ * @param closeable The object to close, may be null or already closed.
+ * @param throwable Add the exception throw by the closeable to the given
Throwable.
+ * @return The given Throwable.
+ * @since 2.22.0
+ * @see Throwable#addSuppressed(Throwable)
+ */
+ public static <T extends Throwable> T closeQuietly(final Closeable
closeable, final T throwable) {
Review Comment:
Honestly I don't understand why the compiler gets confused about
`e::addSuppressed` (which is clearly **not** a `Throwable`), but experimentally
it does.
Any idea why?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]