[
https://issues.apache.org/jira/browse/IO-504?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17210060#comment-17210060
]
Jan Peter Stotz commented on IO-504:
------------------------------------
Sorry but I disagree that IOUtils.closeQuietly() has been marked deprecated.
There are still use cases where try-with-resource can not be applied, e.g. when
you want to implement a method that returns an InputStream and in case of an
error you still have to close the resource the stream is created of. As you
only in case of an error have to close the resource try-with-resource is not
applicable!
Take the following example:
{code:java}
public InputStream getConnectionStream() throws IOException {
Socket socket = new Socket("127.0.0.1", 1234);
InputStream in = socket.getInputStream();
try {
int tag = in.read();
if (tag != 0x10) {
throw new IOException("Invalid tag");
}
return in;
} catch (IOException e) {
IOUtils.closeQuietly(socket);
throw e;
}
}
{code}
Returning the stream and reading/checking something from the stream is not
possible with try-with-resource in one method.
> Deprecated of all IOUtils.closeQuietly() methods and use try-with-resources
> internally
> --------------------------------------------------------------------------------------
>
> Key: IO-504
> URL: https://issues.apache.org/jira/browse/IO-504
> Project: Commons IO
> Issue Type: Wish
> Reporter: Christian Schulte
> Priority: Major
> Fix For: 2.6
>
> Attachments: IO-504.patch, IO-504.patch
>
>
> As soon as 'commons-io' is targetted at Java 7, all 'IOUtils.closeQuietly'
> methods should be deprecated and people should be told to use the
> try-with-resources statement. Those methods are way to error prone and used
> incorrectly almost everywhere. If 'commons-io' has '-target 1.7', keeping
> those methods makes no sense anymore.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)