[
https://issues.apache.org/jira/browse/HADOOP-15085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16284091#comment-16284091
]
Jason Lowe commented on HADOOP-15085:
-------------------------------------
Thanks for the patch!
For input streams we want the close errors to be suppressed because we've read
what we needed to read. Anything else that happens to that stream after that
isn't interesting and shouldn't fail the operation. The same isn't true for
output streams since the things written aren't guaranteed to be persisted until
the close() completes successfully. So the cases where we are using
try-with-resources on input streams is undesirable since we don't want errors
on close to be a problem. In short, we shouldn't apply the code transformation
to input streams, just to the output streams.
bq. The one remaining checkstyle issue is about an empty block in a
try-with-resources block where all the work is done in the resource section.
Nit: I think the code would be a bit more readable if that inner
try-with-resources was just the constructor call followed by a close call to
show it's explicit that the stream is being opened and then immediately closed.
The try-with-resources with an empty block isn't adding readability or brevity
in that case.
> Output streams closed with IOUtils suppressing write errors
> -----------------------------------------------------------
>
> Key: HADOOP-15085
> URL: https://issues.apache.org/jira/browse/HADOOP-15085
> Project: Hadoop Common
> Issue Type: Bug
> Reporter: Jason Lowe
> Assignee: Jim Brennan
> Attachments: HADOOP-15085.001.patch, HADOOP-15085.002.patch
>
>
> There are a few places in hadoop-common that are closing an output stream
> with IOUtils.cleanupWithLogger like this:
> {code}
> try {
> ...write to outStream...
> } finally {
> IOUtils.cleanupWithLogger(LOG, outStream);
> }
> {code}
> This suppresses any IOException that occurs during the close() method which
> could lead to partial/corrupted output without throwing a corresponding
> exception. The code should either use try-with-resources or explicitly close
> the stream within the try block so the exception thrown during close() is
> properly propagated as exceptions during write operations are.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]