Refactor currentThread into local variable 59/38659/3
authorMichael Vorburger <vorburger@redhat.com>
Wed, 11 May 2016 11:08:35 +0000 (13:08 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 11 May 2016 16:37:15 +0000 (16:37 +0000)
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 <vorburger@redhat.com>
common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java

index 41f0c9b472c34f49acd86afbdd7b2c13ee17e78d..b1adba6e479b4bc4b58bc6db58264665019f180f 100644 (file)
@@ -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> V withClassLoader(final ClassLoader cls, final Supplier<V> 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> V withClassLoader(final ClassLoader cls, final Callable<V> 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);
         }
     }