-
Notifications
You must be signed in to change notification settings - Fork 702
Add and use IOUtils.closeQuietly(Closeable, Throwable) #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add and use IOUtils.closeQuietly(Closeable, Throwable) #818
Conversation
|
Nice PR! 💯 I honestly believe this useful method was missing since Java 7 introduced |
| * @since 2.22.0 | ||
| * @see Throwable#addSuppressed(Throwable) | ||
| */ | ||
| public static <T extends Throwable> T closeQuietly(final Closeable closeable, final T throwable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This signature causes the following call to become ambiguous:
closeQuietly(closeable, e::addSuppressed);Maybe we might consider inverting the order of the arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no type casting needed in the call sites in:
- org.apache.commons.io.FileUtils.lineIterator(File, String)
- org.apache.commons.io.LineIterator.hasNext()
- org.apache.commons.io.output.FileWriterWithEncoding.initWriter(File, Object, boolean)
- org.apache.commons.io.IOUtilsTest.testCloseQuietly_CloseableIOExceptionAddSuppressed()
I would only see a typecast needed for a null literal argument, and making the method weird compared to the others for this one use case doesn't seem worth it to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
Add and use IOUtils.closeQuietly(Closeable, Throwable)
mvn; that'smvnon the command line by itself.