procyon
procyon copied to clipboard
SecurityManager is deprecated for removal
SecurityManager is deprecated for removal, see also https://openjdk.org/jeps/486
It is used in procyon in CallerResolver for SecurityManager#getClassContext:
https://github.com/mstrobel/procyon/blob/88a95fa93c58322393174f84543edc7a0a2ca44d/Procyon.Core/src/main/java/com/strobel/compilerservices/CallerResolver.java#L19C43-L19C58
That use-case could be migrated to java.lang.StackWalker, with something like:
public final class CallerResolver {
private static final StackWalker STACK_WALKER =
StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
private static final int CALL_CONTEXT_OFFSET = 1; // may need to change if this class is redesigned
/**
* Indexes into the current method call context with a given offset.
*/
public static Class getCallerClass(final int callerOffset) {
return STACK_WALKER
.walk(
s -> s.skip(CALL_CONTEXT_OFFSET + callerOffset)
.map(StackWalker.StackFrame::getDeclaringClass)
.findFirst())
.get();
}
}
The StackWalker API was added in Java 9, and I think procyon is compatible with JDK 7. To migrate while continuing to support JDK 7 it would be possible to use reflection to access StackWalker, or a multi-release jar.