Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SecurityManager is deprecated for removal #77

Open
cushon opened this issue Dec 6, 2024 · 0 comments
Open

SecurityManager is deprecated for removal #77

cushon opened this issue Dec 6, 2024 · 0 comments

Comments

@cushon
Copy link

cushon commented Dec 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant