-
Notifications
You must be signed in to change notification settings - Fork 713
IOUtils chain together IOException for Closeables, add overload#300
IOUtils chain together IOException for Closeables, add overload #300wodencafe wants to merge 5 commits intoapache:master from
Conversation
95847a1 to
d97b791
Compare
garydgregory
commented
Nov 5, 2021
-1: This makes no sense to me as the exception are not causaly unrelated and you are forcing them to be. This might be a use case for IOExceptionList.
wodencafe
commented
Nov 5, 2021
Hi @garydgregory , good suggestion, IOExceptionList seems like the perfect fit for this. I have revised the code to use this class.
garydgregory
commented
Nov 6, 2021
I ended up reworking the underlying so that now the method looks like this
public static void close(final Closeable... closeables) throws IOException {
IOConsumer.forEach(closeables, IOUtils::close);
}
See also forEachIndex which provides slightly different information for compatibility with other call sites.
garydgregory
commented
Nov 9, 2021
Hi @wodencafe Thank you for your update. Now I see one new method, without any tests, and not used from anywhere.
- Should the [] be changed to a ... and moved to the last parameter position? I would think so.
- Can the method be used within the code base?
- There are no tests.
wodencafe
commented
Nov 9, 2021
Hello @garydgregory , my apologies, I got swamped this weekend and haven't updated this PR with tests. I also agree that the [] should be changed to ... varargs and swapped to be the last parameter, so I will implement this change, and see if there are other places in Commons IO that can take advantage of this new functionality. I will add tests for this today.
Thank you for reviewing the changes, and the contributions and feedback.
03f7fcd to
51759a5
Compare
51759a5 to
8097e96
Compare
d56a425 to
1ccb075
Compare
coveralls
commented
Nov 13, 2021
wodencafe
commented
Nov 13, 2021
Hi @garydgregory , I have updated the pull request with the changes you suggested.
Thank you!
This pull request chains together IOExceptions thrown from closing multiple Closeable instances, which allows the method to attempt to close all of the Closeable instances rather than halting at the first IOException. An overload is added to allow closing multiple Closeable instances and passing the possible resulting IOException to an IOConsumer.