This may be personal taste, but I like the Closer name better.


On Sat, May 24, 2014 at 7:51 AM, Gary Gregory <[email protected]>wrote:

> What about renaming the class SilentCloser and the methods close() if they
> are all "silent"?
>
> Gary
>
>
> -------- Original message --------
> From: [email protected]
> Date:05/23/2014 18:02 (GMT-05:00)
> To: [email protected]
> Subject: svn commit: r1597200 -
> /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/JndiContextSelector.java
>
>
> Author: mattsicker
> Date: Fri May 23 22:02:39 2014
> New Revision: 1597200
>
> URL: http://svn.apache.org/r1597200
> Log:
> Safely close JNDI Context.
>
> Modified:
>
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/JndiContextSelector.java
>
> Modified:
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/JndiContextSelector.java
> URL:
> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/JndiContextSelector.java?rev=1597200&r1=1597199&r2=1597200&view=diff
>
> ==============================================================================
> ---
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/JndiContextSelector.java
> (original)
> +++
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/JndiContextSelector.java
> Fri May 23 22:02:39 2014
> @@ -23,7 +23,6 @@ import java.util.List;
> import java.util.Map;
> import java.util.concurrent.ConcurrentHashMap;
> import java.util.concurrent.ConcurrentMap;
> -
> import javax.naming.Context;
> import javax.naming.InitialContext;
> import javax.naming.NameNotFoundException;
> @@ -31,6 +30,7 @@ import javax.naming.NamingException;
>
> import org.apache.logging.log4j.core.LoggerContext;
> import org.apache.logging.log4j.core.impl.ContextAnchor;
> +import org.apache.logging.log4j.core.util.Closer;
> import org.apache.logging.log4j.core.util.Constants;
> import org.apache.logging.log4j.status.StatusLogger;
>
> @@ -111,11 +111,14 @@ public class JndiContextSelector impleme
>
>          String loggingContextName = null;
>
> +        Context ctx = null;
>          try {
> -            final Context ctx = new InitialContext();
> +            ctx = new InitialContext();
>              loggingContextName = (String) lookup(ctx,
> Constants.JNDI_CONTEXT_NAME);
>          } catch (final NamingException ne) {
>              LOGGER.error("Unable to lookup " +
> Constants.JNDI_CONTEXT_NAME, ne);
> +        } finally {
> +            Closer.closeSilent(ctx);
>          }
>
>          return loggingContextName == null ? CONTEXT :
> locateContext(loggingContextName, null, configLocation);
>
>
>

Reply via email to