Skip to content

Commit

Permalink
Remove unreleased+replaced StackLocator API from LOG4J2-2940
Browse files Browse the repository at this point in the history
  • Loading branch information
carterkozak committed Aug 4, 2021
1 parent 609ff5f commit 59fd1f3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 27 deletions.
Expand Up @@ -62,15 +62,10 @@ public Class<?> getCallerClass(final String fqcn) {
}

public Class<?> getCallerClass(final String fqcn, final String pkg) {
return getCallerClass(fqcn, pkg, 0);
}

public Class<?> getCallerClass(final String fqcn, final String pkg, final int skipDepth) {
return walker.walk(s -> s
.dropWhile(f -> !f.getClassName().equals(fqcn))
.dropWhile(f -> f.getClassName().equals(fqcn))
.dropWhile(f -> !f.getClassName().startsWith(pkg))
.skip(skipDepth)
.findFirst())
.map(StackWalker.StackFrame::getDeclaringClass)
.orElse(null);
Expand Down
Expand Up @@ -140,14 +140,6 @@ public Class<?> getCallerClass(final int depth) {
// migrated from Log4jLoggerFactory
@PerformanceSensitive
public Class<?> getCallerClass(final String fqcn, final String pkg) {
return getCallerClass(fqcn, pkg, 0);
}

@PerformanceSensitive
public Class<?> getCallerClass(final String fqcn, final String pkg, final int skipDepth) {
if (skipDepth < 0) {
throw new IllegalArgumentException("skipDepth cannot be negative");
}
boolean next = false;
Class<?> clazz;
for (int i = 2; null != (clazz = getCallerClass(i)); i++) {
Expand All @@ -156,9 +148,7 @@ public Class<?> getCallerClass(final String fqcn, final String pkg, final int sk
continue;
}
if (next && clazz.getName().startsWith(pkg)) {
return skipDepth == 0
? clazz
: getCallerClass(i + skipDepth);
return clazz;
}
}
// TODO: return Object.class
Expand Down
Expand Up @@ -58,25 +58,16 @@ public static Class<?> getCallerClass(final String fqcn) {
return getCallerClass(fqcn, Strings.EMPTY);
}

/**
* Equivalent to {@link #getCallerClass(String, String, int)} with {@code skipDepth = 0}.
*/
@PerformanceSensitive
public static Class<?> getCallerClass(final String fqcn, final String pkg) {
return stackLocator.getCallerClass(fqcn, pkg);
}

/**
* Search for a calling class.
*
* @param fqcn Root class name whose caller to search for.
* @param pkg Package name prefix that must be matched after the {@code fqcn} has been found.
* @param skipDepth Number of stack frames to skip after the {@code fqcn} and {@code pkg} have been matched.
* @return The caller class that was matched, or null if one could not be located.
*/
@PerformanceSensitive
public static Class<?> getCallerClass(final String fqcn, final String pkg, final int skipDepth) {
return stackLocator.getCallerClass(fqcn, pkg, skipDepth);
public static Class<?> getCallerClass(final String fqcn, final String pkg) {
return stackLocator.getCallerClass(fqcn, pkg);
}

/**
Expand Down

0 comments on commit 59fd1f3

Please sign in to comment.