crunch-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Durfey (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CRUNCH-356) Use IOUtils.closeQuietly instead of Closeables.closeQuietly
Date Tue, 25 Feb 2014 21:41:20 GMT

    [ https://issues.apache.org/jira/browse/CRUNCH-356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13912105#comment-13912105
] 

Stephen Durfey commented on CRUNCH-356:
---------------------------------------

It was decided that if we have an IOException that we wanted to re-throw it, rather than just
log it (I modified the code to log rather than throw a new RTE).

{code}
    /**
     * Performs a null check on the <code>closeable<code> before calling
     * {@link Closeable#close()}. Any thrown {@link IOException} will be
     * caught and logged.
     * 
     * @param closeable
     *            the object to close
     */
    public static void close(@Nullable final Closeable closeable) {
        close(closeable, new StringBuilder("Unable to properly close object of type: ")
                        .append(closeable == null ? null : closeable.getClass().getCanonicalName()).toString());
    }

    /**
     * Performs a null check on the <code>closeable<code> before calling
     * {@link Closeable#close()}. Any thrown {@link IOException} will be
     * caught logged, including the 
     * <code>errorMessage<code> provided.
     * 
     * @param closeable
     *            the object to close
     * @param errorMessage
     *            the error message to include in the thrown RuntimeException
     */
    public static void close(@Nullable final Closeable closeable, final String errorMessage)
{
        try {
            if (closeable != null) {
                closeable.close();
            }
        } catch (final IOException e) {
            LOG.error(errorMessage, e);
        }
    }
{code}
The common use case would be just calling close(), and only calling close() with an error
message is something more specific is needed about the object, or the situation where it was
used. These methods were also enclosed in static class that is just called from the finally
block.

> Use IOUtils.closeQuietly instead of Closeables.closeQuietly
> -----------------------------------------------------------
>
>                 Key: CRUNCH-356
>                 URL: https://issues.apache.org/jira/browse/CRUNCH-356
>             Project: Crunch
>          Issue Type: Improvement
>          Components: Core
>            Reporter: John Leacox
>            Assignee: Josh Wills
>            Priority: Minor
>             Fix For: 0.10.0, 0.8.3
>
>         Attachments: patch.diff
>
>
> Closeables.closeQuietly was deprecated in Guava 13 and removed in Guava 16. If a consumer
of crunch-core is using Guava 16+ a NoSuchMethodError could occur where Closeables.closeQuietly
is being used.
> The other crunch components are already using IOUtils.closeQuietly, so crunch-core could
pull in common-io and use IOUtils.closeQuietly.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Mime
View raw message