mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +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
|
@ -42,25 +42,18 @@ import java.lang.module.ModuleDescriptor;
|
|||
import java.lang.reflect.Executable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.AccessController;
|
||||
import java.security.CodeSource;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.PropertyPermission;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -92,7 +85,6 @@ import jdk.internal.vm.annotation.Stable;
|
|||
import sun.reflect.annotation.AnnotationType;
|
||||
import sun.nio.ch.Interruptible;
|
||||
import sun.nio.cs.UTF_8;
|
||||
import sun.security.util.SecurityConstants;
|
||||
|
||||
/**
|
||||
* The {@code System} class contains several useful class fields
|
||||
|
@ -200,7 +192,6 @@ public final class System {
|
|||
* @since 1.1
|
||||
*/
|
||||
public static void setIn(InputStream in) {
|
||||
checkIO();
|
||||
setIn0(in);
|
||||
}
|
||||
|
||||
|
@ -212,7 +203,6 @@ public final class System {
|
|||
* @since 1.1
|
||||
*/
|
||||
public static void setOut(PrintStream out) {
|
||||
checkIO();
|
||||
setOut0(out);
|
||||
}
|
||||
|
||||
|
@ -224,7 +214,6 @@ public final class System {
|
|||
* @since 1.1
|
||||
*/
|
||||
public static void setErr(PrintStream err) {
|
||||
checkIO();
|
||||
setErr0(err);
|
||||
}
|
||||
|
||||
|
@ -275,32 +264,10 @@ public final class System {
|
|||
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 setOut0(PrintStream out);
|
||||
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
|
||||
* is not supported.
|
||||
|
@ -681,12 +648,6 @@ public final class System {
|
|||
* @see java.util.Properties
|
||||
*/
|
||||
public static Properties getProperties() {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPropertiesAccess();
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
|
@ -725,12 +686,6 @@ public final class System {
|
|||
* @see java.util.Properties
|
||||
*/
|
||||
public static void setProperties(Properties props) {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPropertiesAccess();
|
||||
}
|
||||
|
||||
if (props == null) {
|
||||
Map<String, String> tempProps = SystemProps.initProperties();
|
||||
VersionProps.init(tempProps);
|
||||
|
@ -762,12 +717,6 @@ public final class System {
|
|||
*/
|
||||
public static String getProperty(String key) {
|
||||
checkKey(key);
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPropertyAccess(key);
|
||||
}
|
||||
|
||||
return props.getProperty(key);
|
||||
}
|
||||
|
||||
|
@ -790,12 +739,6 @@ public final class System {
|
|||
*/
|
||||
public static String getProperty(String key, String def) {
|
||||
checkKey(key);
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPropertyAccess(key);
|
||||
}
|
||||
|
||||
return props.getProperty(key, def);
|
||||
}
|
||||
|
||||
|
@ -822,13 +765,6 @@ public final class System {
|
|||
*/
|
||||
public static String setProperty(String key, String value) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -853,12 +789,6 @@ public final class System {
|
|||
*/
|
||||
public static String clearProperty(String key) {
|
||||
checkKey(key);
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new PropertyPermission(key, "write"));
|
||||
}
|
||||
|
||||
return (String) props.remove(key);
|
||||
}
|
||||
|
||||
|
@ -905,12 +835,6 @@ public final class System {
|
|||
* @see ProcessBuilder#environment()
|
||||
*/
|
||||
public static String getenv(String name) {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("getenv."+name));
|
||||
}
|
||||
|
||||
return ProcessEnvironment.getenv(name);
|
||||
}
|
||||
|
||||
|
@ -945,12 +869,6 @@ public final class System {
|
|||
* @since 1.5
|
||||
*/
|
||||
public static java.util.Map<String,String> getenv() {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("getenv.*"));
|
||||
}
|
||||
|
||||
return ProcessEnvironment.getenv();
|
||||
}
|
||||
|
||||
|
@ -1376,13 +1294,6 @@ public final class System {
|
|||
*/
|
||||
@SuppressWarnings("doclint:reference") // cross-module links
|
||||
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}.
|
||||
|
@ -1393,20 +1304,6 @@ public final class System {
|
|||
* loading cycles during the instantiation of the service provider.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public static LoggerFinder getLoggerFinder() {
|
||||
@SuppressWarnings("removal")
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(LOGGERFINDER_PERMISSION);
|
||||
}
|
||||
return accessProvider();
|
||||
}
|
||||
|
||||
|
@ -1493,10 +1385,7 @@ public final class System {
|
|||
// just fetch it again.
|
||||
LoggerFinder finder = service;
|
||||
if (finder == null) {
|
||||
PrivilegedAction<LoggerFinder> pa =
|
||||
() -> LoggerFinderLoader.getLoggerFinder();
|
||||
finder = AccessController.doPrivileged(pa, null,
|
||||
LOGGERFINDER_PERMISSION);
|
||||
finder = LoggerFinderLoader.getLoggerFinder();
|
||||
if (finder instanceof TemporaryLoggerFinder) return finder;
|
||||
service = finder;
|
||||
}
|
||||
|
@ -1602,17 +1491,6 @@ public final class System {
|
|||
if (caller == null) {
|
||||
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()
|
||||
.getLocalizedLogger(name, rb, caller.getModule());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue