mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8344336: SM cleanup of java.lang.System, Runtime, String, StackWalker
Reviewed-by: dfuchs, alanb, lancea
This commit is contained in:
parent
0f458e2c3e
commit
c199f5326b
6 changed files with 14 additions and 219 deletions
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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.
|
* 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() {
|
public static StackWalker getStackWalker() {
|
||||||
return getStackWalker(EnumSet.noneOf(StackWalker.Option.class));
|
return getStackWalker(EnumSet.noneOf(StackWalker.Option.class));
|
||||||
|
@ -171,12 +169,6 @@ interface LiveStackFrame extends StackFrame {
|
||||||
* The returned {@code StackWalker} can get locals and operands.
|
* The returned {@code StackWalker} can get locals and operands.
|
||||||
*
|
*
|
||||||
* @param options stack walk {@link StackWalker.Option options}
|
* @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<StackWalker.Option> options) {
|
public static StackWalker getStackWalker(Set<StackWalker.Option> options) {
|
||||||
return getStackWalker(options, null);
|
return getStackWalker(options, null);
|
||||||
|
@ -193,19 +185,8 @@ interface LiveStackFrame extends StackFrame {
|
||||||
*
|
*
|
||||||
* @param options stack walk {@link StackWalker.Option options}
|
* @param options stack walk {@link StackWalker.Option options}
|
||||||
* @param contScope the continuation scope up to which (inclusive) to walk the stack
|
* @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<StackWalker.Option> options, ContinuationScope contScope) {
|
public static StackWalker getStackWalker(Set<StackWalker.Option> 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);
|
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.
|
* Gets {@code StackWalker} of the given unmounted continuation, that can get locals and operands.
|
||||||
*
|
*
|
||||||
* @param continuation the continuation to walk
|
* @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) {
|
public static StackWalker getStackWalker(Continuation continuation) {
|
||||||
return getStackWalker(EnumSet.noneOf(StackWalker.Option.class), continuation.getScope(), 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 options stack walk {@link StackWalker.Option options}
|
||||||
* @param continuation the continuation to walk
|
* @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<StackWalker.Option> options,
|
public static StackWalker getStackWalker(Set<StackWalker.Option> options,
|
||||||
ContinuationScope contScope,
|
ContinuationScope contScope,
|
||||||
Continuation continuation) {
|
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);
|
return StackWalker.newInstance(options, LOCALS_AND_OPERANDS, contScope, continuation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ import java.lang.reflect.AccessFlag;
|
||||||
import java.lang.reflect.AnnotatedElement;
|
import java.lang.reflect.AnnotatedElement;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.security.CodeSource;
|
||||||
|
import java.security.ProtectionDomain;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -294,11 +296,14 @@ public final class Module implements AnnotatedElement {
|
||||||
String mod = isNamed() ? "module " + getName() : "an unnamed module";
|
String mod = isNamed() ? "module " + getName() : "an unnamed module";
|
||||||
if (currentClass != null) {
|
if (currentClass != null) {
|
||||||
// try to extract location of the current class (e.g. jar or folder)
|
// try to extract location of the current class (e.g. jar or folder)
|
||||||
URL url = System.codeSource(currentClass);
|
CodeSource cs = currentClass.getProtectionDomain().getCodeSource();
|
||||||
|
if (cs != null) {
|
||||||
|
URL url = cs.getLocation();
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
mod += " (" + url + ")";
|
mod += " (" + url + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (illegalNativeAccess == ModuleBootstrap.IllegalNativeAccess.DENY) {
|
if (illegalNativeAccess == ModuleBootstrap.IllegalNativeAccess.DENY) {
|
||||||
throw new IllegalCallerException("Illegal native access from " + mod);
|
throw new IllegalCallerException("Illegal native access from " + mod);
|
||||||
} else if (EnableNativeAccess.trySetEnableNativeAccess(target)) {
|
} else if (EnableNativeAccess.trySetEnableNativeAccess(target)) {
|
||||||
|
|
|
@ -174,11 +174,6 @@ public class Runtime {
|
||||||
* @see #halt(int)
|
* @see #halt(int)
|
||||||
*/
|
*/
|
||||||
public void exit(int status) {
|
public void exit(int status) {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager security = System.getSecurityManager();
|
|
||||||
if (security != null) {
|
|
||||||
security.checkExit(status);
|
|
||||||
}
|
|
||||||
Shutdown.exit(status);
|
Shutdown.exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,11 +227,6 @@ public class Runtime {
|
||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public void addShutdownHook(Thread hook) {
|
public void addShutdownHook(Thread hook) {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = System.getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(new RuntimePermission("shutdownHooks"));
|
|
||||||
}
|
|
||||||
ApplicationShutdownHooks.add(hook);
|
ApplicationShutdownHooks.add(hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,11 +249,6 @@ public class Runtime {
|
||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public boolean removeShutdownHook(Thread hook) {
|
public boolean removeShutdownHook(Thread hook) {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = System.getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(new RuntimePermission("shutdownHooks"));
|
|
||||||
}
|
|
||||||
return ApplicationShutdownHooks.remove(hook);
|
return ApplicationShutdownHooks.remove(hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,11 +278,6 @@ public class Runtime {
|
||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public void halt(int status) {
|
public void halt(int status) {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = System.getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkExit(status);
|
|
||||||
}
|
|
||||||
Shutdown.beforeHalt();
|
Shutdown.beforeHalt();
|
||||||
Shutdown.halt(status);
|
Shutdown.halt(status);
|
||||||
}
|
}
|
||||||
|
@ -779,11 +759,6 @@ public class Runtime {
|
||||||
}
|
}
|
||||||
|
|
||||||
void load0(Class<?> fromClass, String filename) {
|
void load0(Class<?> fromClass, String filename) {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager security = System.getSecurityManager();
|
|
||||||
if (security != null) {
|
|
||||||
security.checkLink(filename);
|
|
||||||
}
|
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
if (!file.isAbsolute()) {
|
if (!file.isAbsolute()) {
|
||||||
throw new UnsatisfiedLinkError(
|
throw new UnsatisfiedLinkError(
|
||||||
|
@ -840,11 +815,6 @@ public class Runtime {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadLibrary0(Class<?> fromClass, String libname) {
|
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) {
|
if (libname.indexOf((int)File.separatorChar) != -1) {
|
||||||
throw new UnsatisfiedLinkError(
|
throw new UnsatisfiedLinkError(
|
||||||
"Directory separator should not appear in library name: " + libname);
|
"Directory separator should not appear in library name: " + libname);
|
||||||
|
|
|
@ -379,7 +379,6 @@ public final class StackWalker {
|
||||||
}
|
}
|
||||||
|
|
||||||
EnumSet<Option> optionSet = toEnumSet(options);
|
EnumSet<Option> optionSet = toEnumSet(options);
|
||||||
checkPermission(optionSet);
|
|
||||||
return new StackWalker(optionSet);
|
return new StackWalker(optionSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,7 +408,6 @@ public final class StackWalker {
|
||||||
throw new IllegalArgumentException("estimateDepth must be > 0");
|
throw new IllegalArgumentException("estimateDepth must be > 0");
|
||||||
}
|
}
|
||||||
EnumSet<Option> optionSet = toEnumSet(options);
|
EnumSet<Option> optionSet = toEnumSet(options);
|
||||||
checkPermission(optionSet);
|
|
||||||
return new StackWalker(optionSet, estimateDepth);
|
return new StackWalker(optionSet, estimateDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,17 +431,6 @@ public final class StackWalker {
|
||||||
this.continuation = continuation;
|
this.continuation = continuation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkPermission(Set<Option> options) {
|
|
||||||
Objects.requireNonNull(options);
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = System.getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
if (options.contains(Option.RETAIN_CLASS_REFERENCE)) {
|
|
||||||
sm.checkPermission(new RuntimePermission("getStackWalkerWithClassReference"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a defensive copy
|
* Returns a defensive copy
|
||||||
*/
|
*/
|
||||||
|
@ -637,7 +624,6 @@ public final class StackWalker {
|
||||||
|
|
||||||
static StackWalker newInstance(Set<Option> options, ExtendedOption extendedOption, ContinuationScope contScope, Continuation continuation) {
|
static StackWalker newInstance(Set<Option> options, ExtendedOption extendedOption, ContinuationScope contScope, Continuation continuation) {
|
||||||
EnumSet<Option> optionSet = toEnumSet(options);
|
EnumSet<Option> optionSet = toEnumSet(options);
|
||||||
checkPermission(optionSet);
|
|
||||||
return new StackWalker(optionSet, 0, extendedOption, contScope, continuation);
|
return new StackWalker(optionSet, 0, extendedOption, contScope, continuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -685,12 +685,6 @@ public final class String
|
||||||
cd.onMalformedInput(CodingErrorAction.REPLACE)
|
cd.onMalformedInput(CodingErrorAction.REPLACE)
|
||||||
.onUnmappableCharacter(CodingErrorAction.REPLACE);
|
.onUnmappableCharacter(CodingErrorAction.REPLACE);
|
||||||
char[] ca = new char[en];
|
char[] ca = new char[en];
|
||||||
if (charset.getClass().getClassLoader0() != null &&
|
|
||||||
System.getSecurityManager() != null) {
|
|
||||||
bytes = Arrays.copyOfRange(bytes, offset, offset + length);
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int caLen;
|
int caLen;
|
||||||
try {
|
try {
|
||||||
caLen = decodeWithDecoder(cd, ca, bytes, offset, length);
|
caLen = decodeWithDecoder(cd, ca, bytes, offset, length);
|
||||||
|
@ -828,10 +822,6 @@ public final class String
|
||||||
}
|
}
|
||||||
int en = scale(len, cd.maxCharsPerByte());
|
int en = scale(len, cd.maxCharsPerByte());
|
||||||
char[] ca = new char[en];
|
char[] ca = new char[en];
|
||||||
if (cs.getClass().getClassLoader0() != null &&
|
|
||||||
System.getSecurityManager() != null) {
|
|
||||||
src = Arrays.copyOf(src, len);
|
|
||||||
}
|
|
||||||
int caLen;
|
int caLen;
|
||||||
try {
|
try {
|
||||||
caLen = decodeWithDecoder(cd, ca, src, 0, src.length);
|
caLen = decodeWithDecoder(cd, ca, src, 0, src.length);
|
||||||
|
@ -850,9 +840,8 @@ public final class String
|
||||||
private static final char REPL = '\ufffd';
|
private static final char REPL = '\ufffd';
|
||||||
|
|
||||||
// Trim the given byte array to the given length
|
// Trim the given byte array to the given length
|
||||||
@SuppressWarnings("removal")
|
private static byte[] trimArray(byte[] ba, int len) {
|
||||||
private static byte[] safeTrim(byte[] ba, int len, boolean isTrusted) {
|
if (len == ba.length) {
|
||||||
if (len == ba.length && (isTrusted || System.getSecurityManager() == null)) {
|
|
||||||
return ba;
|
return ba;
|
||||||
} else {
|
} else {
|
||||||
return Arrays.copyOf(ba, len);
|
return Arrays.copyOf(ba, len);
|
||||||
|
@ -907,7 +896,7 @@ public final class String
|
||||||
int blen = (coder == LATIN1) ? ae.encodeFromLatin1(val, 0, len, ba)
|
int blen = (coder == LATIN1) ? ae.encodeFromLatin1(val, 0, len, ba)
|
||||||
: ae.encodeFromUTF16(val, 0, len, ba);
|
: ae.encodeFromUTF16(val, 0, len, ba);
|
||||||
if (blen != -1) {
|
if (blen != -1) {
|
||||||
return safeTrim(ba, blen, true);
|
return trimArray(ba, blen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -937,7 +926,7 @@ public final class String
|
||||||
throw new Error(x);
|
throw new Error(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return safeTrim(ba, bb.position(), cs.getClass().getClassLoader0() == null);
|
return trimArray(ba, bb.position());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -42,25 +42,18 @@ import java.lang.module.ModuleDescriptor;
|
||||||
import java.lang.reflect.Executable;
|
import java.lang.reflect.Executable;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.channels.Channel;
|
import java.nio.channels.Channel;
|
||||||
import java.nio.channels.spi.SelectorProvider;
|
import java.nio.channels.spi.SelectorProvider;
|
||||||
import java.nio.charset.CharacterCodingException;
|
import java.nio.charset.CharacterCodingException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.CodeSource;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.PropertyPermission;
|
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -92,7 +85,6 @@ import jdk.internal.vm.annotation.Stable;
|
||||||
import sun.reflect.annotation.AnnotationType;
|
import sun.reflect.annotation.AnnotationType;
|
||||||
import sun.nio.ch.Interruptible;
|
import sun.nio.ch.Interruptible;
|
||||||
import sun.nio.cs.UTF_8;
|
import sun.nio.cs.UTF_8;
|
||||||
import sun.security.util.SecurityConstants;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@code System} class contains several useful class fields
|
* The {@code System} class contains several useful class fields
|
||||||
|
@ -200,7 +192,6 @@ public final class System {
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
public static void setIn(InputStream in) {
|
public static void setIn(InputStream in) {
|
||||||
checkIO();
|
|
||||||
setIn0(in);
|
setIn0(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +203,6 @@ public final class System {
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
public static void setOut(PrintStream out) {
|
public static void setOut(PrintStream out) {
|
||||||
checkIO();
|
|
||||||
setOut0(out);
|
setOut0(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +214,6 @@ public final class System {
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
public static void setErr(PrintStream err) {
|
public static void setErr(PrintStream err) {
|
||||||
checkIO();
|
|
||||||
setErr0(err);
|
setErr0(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,32 +264,10 @@ public final class System {
|
||||||
return SelectorProvider.provider().inheritedChannel();
|
return SelectorProvider.provider().inheritedChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkIO() {
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(new RuntimePermission("setIO"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static native void setIn0(InputStream in);
|
private static native void setIn0(InputStream in);
|
||||||
private static native void setOut0(PrintStream out);
|
private static native void setOut0(PrintStream out);
|
||||||
private static native void setErr0(PrintStream err);
|
private static native void setErr0(PrintStream err);
|
||||||
|
|
||||||
private static class CallersHolder {
|
|
||||||
// Remember callers of setSecurityManager() here so that warning
|
|
||||||
// is only printed once for each different caller
|
|
||||||
static final Map<Class<?>, Boolean> callers
|
|
||||||
= Collections.synchronizedMap(new WeakHashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
static URL codeSource(Class<?> clazz) {
|
|
||||||
PrivilegedAction<ProtectionDomain> pa = clazz::getProtectionDomain;
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
CodeSource cs = AccessController.doPrivileged(pa).getCodeSource();
|
|
||||||
return (cs != null) ? cs.getLocation() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws {@code UnsupportedOperationException}. Setting a security manager
|
* Throws {@code UnsupportedOperationException}. Setting a security manager
|
||||||
* is not supported.
|
* is not supported.
|
||||||
|
@ -681,12 +648,6 @@ public final class System {
|
||||||
* @see java.util.Properties
|
* @see java.util.Properties
|
||||||
*/
|
*/
|
||||||
public static Properties getProperties() {
|
public static Properties getProperties() {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPropertiesAccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -725,12 +686,6 @@ public final class System {
|
||||||
* @see java.util.Properties
|
* @see java.util.Properties
|
||||||
*/
|
*/
|
||||||
public static void setProperties(Properties props) {
|
public static void setProperties(Properties props) {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPropertiesAccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props == null) {
|
if (props == null) {
|
||||||
Map<String, String> tempProps = SystemProps.initProperties();
|
Map<String, String> tempProps = SystemProps.initProperties();
|
||||||
VersionProps.init(tempProps);
|
VersionProps.init(tempProps);
|
||||||
|
@ -762,12 +717,6 @@ public final class System {
|
||||||
*/
|
*/
|
||||||
public static String getProperty(String key) {
|
public static String getProperty(String key) {
|
||||||
checkKey(key);
|
checkKey(key);
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPropertyAccess(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return props.getProperty(key);
|
return props.getProperty(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,12 +739,6 @@ public final class System {
|
||||||
*/
|
*/
|
||||||
public static String getProperty(String key, String def) {
|
public static String getProperty(String key, String def) {
|
||||||
checkKey(key);
|
checkKey(key);
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPropertyAccess(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return props.getProperty(key, def);
|
return props.getProperty(key, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -822,13 +765,6 @@ public final class System {
|
||||||
*/
|
*/
|
||||||
public static String setProperty(String key, String value) {
|
public static String setProperty(String key, String value) {
|
||||||
checkKey(key);
|
checkKey(key);
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(new PropertyPermission(key,
|
|
||||||
SecurityConstants.PROPERTY_WRITE_ACTION));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (String) props.setProperty(key, value);
|
return (String) props.setProperty(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,12 +789,6 @@ public final class System {
|
||||||
*/
|
*/
|
||||||
public static String clearProperty(String key) {
|
public static String clearProperty(String key) {
|
||||||
checkKey(key);
|
checkKey(key);
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(new PropertyPermission(key, "write"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (String) props.remove(key);
|
return (String) props.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -905,12 +835,6 @@ public final class System {
|
||||||
* @see ProcessBuilder#environment()
|
* @see ProcessBuilder#environment()
|
||||||
*/
|
*/
|
||||||
public static String getenv(String name) {
|
public static String getenv(String name) {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(new RuntimePermission("getenv."+name));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessEnvironment.getenv(name);
|
return ProcessEnvironment.getenv(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,12 +869,6 @@ public final class System {
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public static java.util.Map<String,String> getenv() {
|
public static java.util.Map<String,String> getenv() {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
SecurityManager sm = getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(new RuntimePermission("getenv.*"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProcessEnvironment.getenv();
|
return ProcessEnvironment.getenv();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1376,13 +1294,6 @@ public final class System {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("doclint:reference") // cross-module links
|
@SuppressWarnings("doclint:reference") // cross-module links
|
||||||
public abstract static class LoggerFinder {
|
public abstract static class LoggerFinder {
|
||||||
/**
|
|
||||||
* The {@code RuntimePermission("loggerFinder")} is
|
|
||||||
* necessary to subclass and instantiate the {@code LoggerFinder} class,
|
|
||||||
* as well as to obtain loggers from an instance of that class.
|
|
||||||
*/
|
|
||||||
static final RuntimePermission LOGGERFINDER_PERMISSION =
|
|
||||||
new RuntimePermission("loggerFinder");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of {@code LoggerFinder}.
|
* Creates a new instance of {@code LoggerFinder}.
|
||||||
|
@ -1393,20 +1304,6 @@ public final class System {
|
||||||
* loading cycles during the instantiation of the service provider.
|
* loading cycles during the instantiation of the service provider.
|
||||||
*/
|
*/
|
||||||
protected LoggerFinder() {
|
protected LoggerFinder() {
|
||||||
this(checkPermission());
|
|
||||||
}
|
|
||||||
|
|
||||||
private LoggerFinder(Void unused) {
|
|
||||||
// nothing to do.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Void checkPermission() {
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
final SecurityManager sm = System.getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(LOGGERFINDER_PERMISSION);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1476,11 +1373,6 @@ public final class System {
|
||||||
* @return the {@link LoggerFinder LoggerFinder} instance.
|
* @return the {@link LoggerFinder LoggerFinder} instance.
|
||||||
*/
|
*/
|
||||||
public static LoggerFinder getLoggerFinder() {
|
public static LoggerFinder getLoggerFinder() {
|
||||||
@SuppressWarnings("removal")
|
|
||||||
final SecurityManager sm = System.getSecurityManager();
|
|
||||||
if (sm != null) {
|
|
||||||
sm.checkPermission(LOGGERFINDER_PERMISSION);
|
|
||||||
}
|
|
||||||
return accessProvider();
|
return accessProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1493,10 +1385,7 @@ public final class System {
|
||||||
// just fetch it again.
|
// just fetch it again.
|
||||||
LoggerFinder finder = service;
|
LoggerFinder finder = service;
|
||||||
if (finder == null) {
|
if (finder == null) {
|
||||||
PrivilegedAction<LoggerFinder> pa =
|
finder = LoggerFinderLoader.getLoggerFinder();
|
||||||
() -> LoggerFinderLoader.getLoggerFinder();
|
|
||||||
finder = AccessController.doPrivileged(pa, null,
|
|
||||||
LOGGERFINDER_PERMISSION);
|
|
||||||
if (finder instanceof TemporaryLoggerFinder) return finder;
|
if (finder instanceof TemporaryLoggerFinder) return finder;
|
||||||
service = finder;
|
service = finder;
|
||||||
}
|
}
|
||||||
|
@ -1602,17 +1491,6 @@ public final class System {
|
||||||
if (caller == null) {
|
if (caller == null) {
|
||||||
throw new IllegalCallerException("no caller frame");
|
throw new IllegalCallerException("no caller frame");
|
||||||
}
|
}
|
||||||
final SecurityManager sm = System.getSecurityManager();
|
|
||||||
// We don't use LazyLoggers if a resource bundle is specified.
|
|
||||||
// Bootstrap sensitive classes in the JDK do not use resource bundles
|
|
||||||
// when logging. This could be revisited later, if it needs to.
|
|
||||||
if (sm != null) {
|
|
||||||
final PrivilegedAction<Logger> pa =
|
|
||||||
() -> LoggerFinder.accessProvider()
|
|
||||||
.getLocalizedLogger(name, rb, caller.getModule());
|
|
||||||
return AccessController.doPrivileged(pa, null,
|
|
||||||
LoggerFinder.LOGGERFINDER_PERMISSION);
|
|
||||||
}
|
|
||||||
return LoggerFinder.accessProvider()
|
return LoggerFinder.accessProvider()
|
||||||
.getLocalizedLogger(name, rb, caller.getModule());
|
.getLocalizedLogger(name, rb, caller.getModule());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue