Use LoaderUtil.loadClass().
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2d732034 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2d732034 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2d732034 Branch: refs/heads/master Commit: 2d73203439fa32aa3c21019f154bb5aa2748d240 Parents: 3c9a265 Author: Matt Sicker <[email protected]> Authored: Sun Sep 21 12:00:29 2014 -0500 Committer: Matt Sicker <[email protected]> Committed: Sun Sep 21 12:00:29 2014 -0500 ---------------------------------------------------------------------- .../java/org/apache/logging/log4j/util/ReflectionUtil.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d732034/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionUtil.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionUtil.java index c9e010b..3d95e78 100644 --- a/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionUtil.java +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/ReflectionUtil.java @@ -60,8 +60,7 @@ public final class ReflectionUtil { Method getCallerClass; int java7u25CompensationOffset = 0; try { - final Class<?> sunReflectionClass = LoaderUtil.getThreadContextClassLoader().loadClass( - "sun.reflect.Reflection"); + final Class<?> sunReflectionClass = LoaderUtil.loadClass("sun.reflect.Reflection"); getCallerClass = sunReflectionClass.getDeclaredMethod("getCallerClass", int.class); Object o = getCallerClass.invoke(null, 0); final Object test1 = getCallerClass.invoke(null, 0); @@ -132,9 +131,8 @@ public final class ReflectionUtil { // TODO: SecurityManager-based version? // slower fallback method using stack trace final StackTraceElement element = getEquivalentStackTraceElement(depth + 1); - final ClassLoader cl = LoaderUtil.getThreadContextClassLoader(); try { - return cl.loadClass(element.getClassName()); + return LoaderUtil.loadClass(element.getClassName()); } catch (final ClassNotFoundException e) { LOGGER.error("Could not find class in ReflectionUtil.getCallerClass({}).", depth, e); } @@ -218,7 +216,7 @@ public final class ReflectionUtil { continue; } if (next) { - return LoaderUtil.getThreadContextClassLoader().loadClass(className); + return LoaderUtil.loadClass(className); } } } catch (final ClassNotFoundException ignored) {
