From 38117ff74bff9c0a4e1a803185868e61e20e25c6 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Wed, 11 May 2016 13:08:35 +0200 Subject: [PATCH] Refactor currentThread into local variable Not that this would fix anything, as Thread.currentThread() shouldn't change here (or could it?), so consider this more of a "readability" proposal. Change-Id: I70ef77f4d2b6e34440168456c0638be6c7045f79 Signed-off-by: Michael Vorburger --- .../yangtools/util/ClassLoaderUtils.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java index 41f0c9b472..b1adba6e47 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java @@ -30,7 +30,6 @@ public final class ClassLoaderUtils { } /** - * * Runs {@link Supplier} with provided {@link ClassLoader}. * * Invokes supplies function and makes sure that original {@link ClassLoader} @@ -39,23 +38,22 @@ public final class ClassLoaderUtils { * @param cls {@link ClassLoader} to be used. * @param function Function to be executed. * @return Result of supplier invocation. - * */ public static V withClassLoader(final ClassLoader cls, final Supplier function) { checkNotNull(cls, "Classloader should not be null"); checkNotNull(function, "Function should not be null"); - final ClassLoader oldCls = Thread.currentThread().getContextClassLoader(); + final Thread currentThread = Thread.currentThread(); + final ClassLoader oldCls = currentThread.getContextClassLoader(); try { - Thread.currentThread().setContextClassLoader(cls); + currentThread.setContextClassLoader(cls); return function.get(); } finally { - Thread.currentThread().setContextClassLoader(oldCls); + currentThread.setContextClassLoader(oldCls); } } /** - * * Runs {@link Callable} with provided {@link ClassLoader}. * * Invokes supplies function and makes sure that original {@link ClassLoader} @@ -64,18 +62,18 @@ public final class ClassLoaderUtils { * @param cls {@link ClassLoader} to be used. * @param function Function to be executed. * @return Result of callable invocation. - * */ public static V withClassLoader(final ClassLoader cls, final Callable function) throws Exception { checkNotNull(cls, "Classloader should not be null"); checkNotNull(function, "Function should not be null"); - final ClassLoader oldCls = Thread.currentThread().getContextClassLoader(); + final Thread currentThread = Thread.currentThread(); + final ClassLoader oldCls = currentThread.getContextClassLoader(); try { - Thread.currentThread().setContextClassLoader(cls); + currentThread.setContextClassLoader(cls); return function.call(); } finally { - Thread.currentThread().setContextClassLoader(oldCls); + currentThread.setContextClassLoader(oldCls); } } -- 2.36.6