This commit is contained in:
Jesper Wilhelmsson 2021-06-23 01:05:44 +00:00
commit b6cfca8a89
59 changed files with 810 additions and 1218 deletions

View file

@ -44,14 +44,16 @@ import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URL;
import java.nio.charset.CharacterCodingException;
import java.security.AccessControlContext;
import java.security.ProtectionDomain;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.nio.channels.Channel;
import java.nio.channels.spi.SelectorProvider;
import java.nio.charset.Charset;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -324,6 +326,16 @@ public final class System {
private static native void setOut0(PrintStream out);
private static native void setErr0(PrintStream err);
// Remember initial System.err. setSecurityManager() warning goes here
private static volatile @Stable PrintStream initialErrStream;
private static URL codeSource(Class<?> clazz) {
PrivilegedAction<ProtectionDomain> pa = clazz::getProtectionDomain;
@SuppressWarnings("removal")
CodeSource cs = AccessController.doPrivileged(pa).getCodeSource();
return (cs != null) ? cs.getLocation() : null;
}
/**
* Sets the system-wide security manager.
*
@ -362,16 +374,29 @@ public final class System {
* method.
*/
@Deprecated(since="17", forRemoval=true)
@CallerSensitive
public static void setSecurityManager(@SuppressWarnings("removal") SecurityManager sm) {
if (allowSecurityManager()) {
System.err.println("WARNING: java.lang.System::setSecurityManager" +
" is deprecated and will be removed in a future release.");
var callerClass = Reflection.getCallerClass();
URL url = codeSource(callerClass);
final String source;
if (url == null) {
source = callerClass.getName();
} else {
source = callerClass.getName() + " (" + url + ")";
}
initialErrStream.printf("""
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by %s
WARNING: Please consider reporting this to the maintainers of %s
WARNING: System::setSecurityManager will be removed in a future release
""", source, callerClass.getName());
implSetSecurityManager(sm);
} else {
// security manager not allowed
if (sm != null) {
throw new UnsupportedOperationException(
"Runtime configured to disallow security manager");
"The Security Manager is deprecated and will be removed in a future release");
}
}
}
@ -2191,10 +2216,13 @@ public final class System {
}
if (needWarning) {
System.err.println("WARNING: The Security Manager is deprecated" +
" and will be removed in a future release.");
System.err.println("""
WARNING: A command line option has enabled the Security Manager
WARNING: The Security Manager is deprecated and will be removed in a future release""");
}
initialErrStream = System.err;
// initializing the system class loader
VM.initLevel(3);

View file

@ -105,7 +105,7 @@ public sealed interface DirectMethodHandleDesc
* @throws IllegalArgumentException if there is no such member
*/
public static Kind valueOf(int refKind) {
return valueOf(refKind, false);
return valueOf(refKind, refKind == REF_invokeInterface);
}
/**
@ -134,16 +134,10 @@ public sealed interface DirectMethodHandleDesc
*/
public static Kind valueOf(int refKind, boolean isInterface) {
int i = tableIndex(refKind, isInterface);
if (i >= 0 && i < TABLE.length) {
Kind kind = TABLE[i];
if (kind == null) {
throw new IllegalArgumentException(String.format("refKind=%d", refKind));
}
if (kind.refKind == refKind && kind.isInterface == isInterface) {
return kind;
}
if (i >= 2 && i < TABLE.length) {
return TABLE[i];
}
throw new IllegalArgumentException(String.format("refKind=%d", refKind));
throw new IllegalArgumentException(String.format("refKind=%d isInterface=%s", refKind, isInterface));
}
private static int tableIndex(int refKind, boolean isInterface) {
@ -180,9 +174,7 @@ public sealed interface DirectMethodHandleDesc
// for either truth value of X.
int i = tableIndex(kind.refKind, true);
if (TABLE[i] == null) {
// There is not a specific Kind for interfaces
if (kind == VIRTUAL) kind = INTERFACE_VIRTUAL;
if (TABLE[i] == null) TABLE[i] = kind;
TABLE[i] = kind;
}
}
}