diff --git a/src/java.base/share/classes/java/lang/LiveStackFrame.java b/src/java.base/share/classes/java/lang/LiveStackFrame.java index 77a02d083c8..7b61d191e3b 100644 --- a/src/java.base/share/classes/java/lang/LiveStackFrame.java +++ b/src/java.base/share/classes/java/lang/LiveStackFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -154,8 +154,6 @@ interface LiveStackFrame extends StackFrame { /** * Gets {@code StackWalker} that can get locals and operands. * - * @throws SecurityException if the security manager is present and - * denies access to {@code RuntimePermission("liveStackFrames")} */ public static StackWalker getStackWalker() { return getStackWalker(EnumSet.noneOf(StackWalker.Option.class)); @@ -171,12 +169,6 @@ interface LiveStackFrame extends StackFrame { * The returned {@code StackWalker} can get locals and operands. * * @param options stack walk {@link StackWalker.Option options} - * - * @throws SecurityException if the security manager is present and - * it denies access to {@code RuntimePermission("liveStackFrames")}; - * or if the given {@code options} contains - * {@link StackWalker.Option#RETAIN_CLASS_REFERENCE Option.RETAIN_CLASS_REFERENCE} - * and it denies access to {@code RuntimePermission("getStackWalkerWithClassReference")}. */ public static StackWalker getStackWalker(Set options) { return getStackWalker(options, null); @@ -193,19 +185,8 @@ interface LiveStackFrame extends StackFrame { * * @param options stack walk {@link StackWalker.Option options} * @param contScope the continuation scope up to which (inclusive) to walk the stack - * - * @throws SecurityException if the security manager is present and - * it denies access to {@code RuntimePermission("liveStackFrames")}; or - * or if the given {@code options} contains - * {@link StackWalker.Option#RETAIN_CLASS_REFERENCE Option.RETAIN_CLASS_REFERENCE} - * and it denies access to {@code RuntimePermission("getStackWalkerWithClassReference")}. */ public static StackWalker getStackWalker(Set options, ContinuationScope contScope) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("liveStackFrames")); - } return StackWalker.newInstance(options, LOCALS_AND_OPERANDS, contScope); } @@ -213,9 +194,6 @@ interface LiveStackFrame extends StackFrame { * Gets {@code StackWalker} of the given unmounted continuation, that can get locals and operands. * * @param continuation the continuation to walk - * - * @throws SecurityException if the security manager is present and - * denies access to {@code RuntimePermission("liveStackFrames")} */ public static StackWalker getStackWalker(Continuation continuation) { return getStackWalker(EnumSet.noneOf(StackWalker.Option.class), continuation.getScope(), continuation); @@ -232,21 +210,10 @@ interface LiveStackFrame extends StackFrame { * * @param options stack walk {@link StackWalker.Option options} * @param continuation the continuation to walk - * - * @throws SecurityException if the security manager is present and - * it denies access to {@code RuntimePermission("liveStackFrames")}; or - * or if the given {@code options} contains - * {@link StackWalker.Option#RETAIN_CLASS_REFERENCE Option.RETAIN_CLASS_REFERENCE} - * and it denies access to {@code RuntimePermission("getStackWalkerWithClassReference")}. */ public static StackWalker getStackWalker(Set options, ContinuationScope contScope, Continuation continuation) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("liveStackFrames")); - } return StackWalker.newInstance(options, LOCALS_AND_OPERANDS, contScope, continuation); } } diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java index 4f9c09bace4..dcc92d012de 100644 --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -39,6 +39,8 @@ import java.lang.reflect.AccessFlag; import java.lang.reflect.AnnotatedElement; import java.net.URI; import java.net.URL; +import java.security.CodeSource; +import java.security.ProtectionDomain; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -294,9 +296,12 @@ public final class Module implements AnnotatedElement { String mod = isNamed() ? "module " + getName() : "an unnamed module"; if (currentClass != null) { // try to extract location of the current class (e.g. jar or folder) - URL url = System.codeSource(currentClass); - if (url != null) { - mod += " (" + url + ")"; + CodeSource cs = currentClass.getProtectionDomain().getCodeSource(); + if (cs != null) { + URL url = cs.getLocation(); + if (url != null) { + mod += " (" + url + ")"; + } } } if (illegalNativeAccess == ModuleBootstrap.IllegalNativeAccess.DENY) { diff --git a/src/java.base/share/classes/java/lang/Runtime.java b/src/java.base/share/classes/java/lang/Runtime.java index 2f8f003af7c..764a9d7fa63 100644 --- a/src/java.base/share/classes/java/lang/Runtime.java +++ b/src/java.base/share/classes/java/lang/Runtime.java @@ -174,11 +174,6 @@ public class Runtime { * @see #halt(int) */ public void exit(int status) { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkExit(status); - } Shutdown.exit(status); } @@ -232,11 +227,6 @@ public class Runtime { * @since 1.3 */ public void addShutdownHook(Thread hook) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("shutdownHooks")); - } ApplicationShutdownHooks.add(hook); } @@ -259,11 +249,6 @@ public class Runtime { * @since 1.3 */ public boolean removeShutdownHook(Thread hook) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("shutdownHooks")); - } return ApplicationShutdownHooks.remove(hook); } @@ -293,11 +278,6 @@ public class Runtime { * @since 1.3 */ public void halt(int status) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkExit(status); - } Shutdown.beforeHalt(); Shutdown.halt(status); } @@ -779,11 +759,6 @@ public class Runtime { } void load0(Class fromClass, String filename) { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkLink(filename); - } File file = new File(filename); if (!file.isAbsolute()) { throw new UnsatisfiedLinkError( @@ -840,11 +815,6 @@ public class Runtime { } void loadLibrary0(Class fromClass, String libname) { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkLink(libname); - } if (libname.indexOf((int)File.separatorChar) != -1) { throw new UnsatisfiedLinkError( "Directory separator should not appear in library name: " + libname); diff --git a/src/java.base/share/classes/java/lang/StackWalker.java b/src/java.base/share/classes/java/lang/StackWalker.java index a6756f3278b..0c6e400b2fb 100644 --- a/src/java.base/share/classes/java/lang/StackWalker.java +++ b/src/java.base/share/classes/java/lang/StackWalker.java @@ -379,7 +379,6 @@ public final class StackWalker { } EnumSet