Move ReflectionUtil feature from log4j-slf4j-impl.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c91070ab Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c91070ab Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c91070ab Branch: refs/heads/master Commit: c91070abf0c103e0254dbae12dea3e2defce9625 Parents: 599c1f0 Author: Matt Sicker <[email protected]> Authored: Sat Oct 4 10:41:17 2014 -0500 Committer: Matt Sicker <[email protected]> Committed: Sat Oct 4 10:41:17 2014 -0500 ---------------------------------------------------------------------- .../apache/logging/log4j/util/ReflectionUtil.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c91070ab/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 89e7a20..ad707c7 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 @@ -185,6 +185,11 @@ public final class ReflectionUtil { // migrated from ClassLoaderContextSelector public static Class<?> getCallerClass(final String fqcn) { + return getCallerClass(fqcn, ""); + } + + // migrated from Log4jLoggerFactory + public static Class<?> getCallerClass(final String fqcn, final String pkg) { if (supportsFastReflection()) { boolean next = false; Class<?> clazz; @@ -193,14 +198,14 @@ public final class ReflectionUtil { next = true; continue; } - if (next) { + if (next && clazz.getName().startsWith(pkg)) { return clazz; } } return null; } if (SECURITY_MANAGER != null) { - return SECURITY_MANAGER.getCallerClass(fqcn); + return SECURITY_MANAGER.getCallerClass(fqcn, pkg); } boolean next = false; final StackTraceElement[] elements = new Throwable().getStackTrace(); @@ -211,7 +216,7 @@ public final class ReflectionUtil { next = true; continue; } - if (next) { + if (next && className.startsWith(pkg)) { return LoaderUtil.loadClass(className); } } @@ -252,7 +257,7 @@ public final class ReflectionUtil { return super.getClassContext(); } - protected Class<?> getCallerClass(final String fqcn) { + protected Class<?> getCallerClass(final String fqcn, final String pkg) { final Class<?>[] classes = getClassContext(); boolean next = false; for (final Class<?> clazz : classes) { @@ -260,7 +265,7 @@ public final class ReflectionUtil { next = true; continue; } - if (next) { + if (next && clazz.getName().startsWith(pkg)) { return clazz; } }
