Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

IOUtils chain together IOException for Closeables, add overload#300

Open
wodencafe wants to merge 5 commits intoapache:master from
wodencafe:IOUtils-closewitherrors
Open

IOUtils chain together IOException for Closeables, add overload #300
wodencafe wants to merge 5 commits intoapache:master from
wodencafe:IOUtils-closewitherrors

Conversation

@wodencafe
Copy link
Contributor

@wodencafe wodencafe commented Nov 5, 2021

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.

Copy link
Member

-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.

Copy link
Contributor Author

Hi @garydgregory , good suggestion, IOExceptionList seems like the perfect fit for this. I have revised the code to use this class.

Copy link
Member

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.

wodencafe reacted with thumbs up emoji

Copy link
Member

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 reacted with thumbs up emoji

Copy link
Contributor Author

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.

@wodencafe wodencafe force-pushed the IOUtils-closewitherrors branch 4 times, most recently from 03f7fcd to 51759a5 Compare November 11, 2021 15:42
Copy link

Coverage Status

Coverage decreased (-0.5%) to 87.329% when pulling 1ccb075 on wodencafe:IOUtils-closewitherrors into 5300267 on apache:master.

Copy link
Contributor Author

Hi @garydgregory , I have updated the pull request with the changes you suggested.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jochenw jochenw jochenw left review comments

@garydgregory garydgregory Awaiting requested review from garydgregory

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /