8344289: SM cleanup in jdk.internal.util
Reviewed-by: liach, rriggs, bpb
This commit is contained in:
parent
a91d4c022f
commit
d0b770c938
@ -29,8 +29,6 @@ import jdk.internal.misc.VM;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import java.util.HexFormat;
|
import java.util.HexFormat;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -79,10 +77,6 @@ public final class ClassFileDumper {
|
|||||||
private final AtomicInteger counter = new AtomicInteger();
|
private final AtomicInteger counter = new AtomicInteger();
|
||||||
|
|
||||||
private ClassFileDumper(String key, String path) {
|
private ClassFileDumper(String key, String path) {
|
||||||
/*
|
|
||||||
* GetPropertyAction.privilegedGetProperty cannot be used here, Using VM.getSavedProperty to avoid a bootstrap
|
|
||||||
* circularity issue in the java/lang/String/concat/WithSecurityManager.java test
|
|
||||||
*/
|
|
||||||
String value = VM.getSavedProperty(key);
|
String value = VM.getSavedProperty(key);
|
||||||
this.key = key;
|
this.key = key;
|
||||||
boolean enabled = value != null && value.isEmpty() ? true : Boolean.parseBoolean(value);
|
boolean enabled = value != null && value.isEmpty() ? true : Boolean.parseBoolean(value);
|
||||||
@ -132,10 +126,7 @@ public final class ClassFileDumper {
|
|||||||
write(pathname(name + ".failed-" + counter.incrementAndGet()), bytes);
|
write(pathname(name + ".failed-" + counter.incrementAndGet()), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private void write(Path path, byte[] bytes) {
|
private void write(Path path, byte[] bytes) {
|
||||||
AccessController.doPrivileged(new PrivilegedAction<>() {
|
|
||||||
@Override public Void run() {
|
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(path.getParent());
|
Files.createDirectories(path.getParent());
|
||||||
Files.write(path, bytes);
|
Files.write(path, bytes);
|
||||||
@ -148,18 +139,12 @@ public final class ClassFileDumper {
|
|||||||
}
|
}
|
||||||
// simply don't care if this operation failed
|
// simply don't care if this operation failed
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Validate if the given dir is a writeable directory if exists.
|
* Validate if the given dir is a writeable directory if exists.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private static Path validateDumpDir(String dir) {
|
private static Path validateDumpDir(String dir) {
|
||||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
|
||||||
@Override
|
|
||||||
public Path run() {
|
|
||||||
Path path = Path.of(dir);
|
Path path = Path.of(dir);
|
||||||
if (Files.notExists(path)) {
|
if (Files.notExists(path)) {
|
||||||
try {
|
try {
|
||||||
@ -175,8 +160,6 @@ public final class ClassFileDumper {
|
|||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final HexFormat HEX = HexFormat.of().withUpperCase();
|
private static final HexFormat HEX = HexFormat.of().withUpperCase();
|
||||||
private static final Set<Character> BAD_CHARS = Set.of('\\', ':', '*', '?', '"', '<', '>', '|');
|
private static final Set<Character> BAD_CHARS = Set.of('\\', ':', '*', '?', '"', '<', '>', '|');
|
||||||
|
@ -32,14 +32,11 @@ import java.util.Properties;
|
|||||||
* Read-only access to System property values initialized during Phase 1
|
* Read-only access to System property values initialized during Phase 1
|
||||||
* are cached. Setting, clearing, or modifying the value using
|
* are cached. Setting, clearing, or modifying the value using
|
||||||
* {@link System#setProperty} or {@link System#getProperties()} is ignored.
|
* {@link System#setProperty} or {@link System#getProperties()} is ignored.
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in these access methods. The caller of these methods should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public final class StaticProperty {
|
public final class StaticProperty {
|
||||||
|
|
||||||
// The class static initialization is triggered to initialize these final
|
// The class static initialization is triggered to initialize these final
|
||||||
// fields during init Phase 1 and before a security manager is set.
|
// fields during init Phase 1.
|
||||||
private static final String JAVA_HOME;
|
private static final String JAVA_HOME;
|
||||||
private static final String USER_HOME;
|
private static final String USER_HOME;
|
||||||
private static final String USER_DIR;
|
private static final String USER_DIR;
|
||||||
@ -143,10 +140,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code java.home} system property}
|
* {@return the {@code java.home} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String javaHome() {
|
public static String javaHome() {
|
||||||
return JAVA_HOME;
|
return JAVA_HOME;
|
||||||
@ -154,10 +147,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code user.home} system property}
|
* {@return the {@code user.home} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String userHome() {
|
public static String userHome() {
|
||||||
return USER_HOME;
|
return USER_HOME;
|
||||||
@ -165,10 +154,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code user.dir} system property}
|
* {@return the {@code user.dir} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String userDir() {
|
public static String userDir() {
|
||||||
return USER_DIR;
|
return USER_DIR;
|
||||||
@ -176,10 +161,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code user.name} system property}
|
* {@return the {@code user.name} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String userName() {
|
public static String userName() {
|
||||||
return USER_NAME;
|
return USER_NAME;
|
||||||
@ -187,10 +168,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code java.library.path} system property}
|
* {@return the {@code java.library.path} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String javaLibraryPath() {
|
public static String javaLibraryPath() {
|
||||||
return JAVA_LIBRARY_PATH;
|
return JAVA_LIBRARY_PATH;
|
||||||
@ -198,10 +175,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code java.io.tmpdir} system property}
|
* {@return the {@code java.io.tmpdir} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String javaIoTmpDir() {
|
public static String javaIoTmpDir() {
|
||||||
return JAVA_IO_TMPDIR;
|
return JAVA_IO_TMPDIR;
|
||||||
@ -209,10 +182,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code sun.boot.library.path} system property}
|
* {@return the {@code sun.boot.library.path} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String sunBootLibraryPath() {
|
public static String sunBootLibraryPath() {
|
||||||
return SUN_BOOT_LIBRARY_PATH;
|
return SUN_BOOT_LIBRARY_PATH;
|
||||||
@ -221,10 +190,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code jdk.serialFilter} system property}
|
* {@return the {@code jdk.serialFilter} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String jdkSerialFilter() {
|
public static String jdkSerialFilter() {
|
||||||
return JDK_SERIAL_FILTER;
|
return JDK_SERIAL_FILTER;
|
||||||
@ -233,10 +198,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code jdk.serialFilterFactory} system property}
|
* {@return the {@code jdk.serialFilterFactory} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String jdkSerialFilterFactory() {
|
public static String jdkSerialFilterFactory() {
|
||||||
return JDK_SERIAL_FILTER_FACTORY;
|
return JDK_SERIAL_FILTER_FACTORY;
|
||||||
@ -244,10 +205,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code native.encoding} system property}
|
* {@return the {@code native.encoding} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String nativeEncoding() {
|
public static String nativeEncoding() {
|
||||||
return NATIVE_ENCODING;
|
return NATIVE_ENCODING;
|
||||||
@ -255,10 +212,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code file.encoding} system property}
|
* {@return the {@code file.encoding} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String fileEncoding() {
|
public static String fileEncoding() {
|
||||||
return FILE_ENCODING;
|
return FILE_ENCODING;
|
||||||
@ -266,9 +219,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code java.properties.date} system property}
|
* {@return the {@code java.properties.date} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String javaPropertiesDate() {
|
public static String javaPropertiesDate() {
|
||||||
return JAVA_PROPERTIES_DATE;
|
return JAVA_PROPERTIES_DATE;
|
||||||
@ -276,10 +226,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code sun.jnu.encoding} system property}
|
* {@return the {@code sun.jnu.encoding} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String jnuEncoding() {
|
public static String jnuEncoding() {
|
||||||
return SUN_JNU_ENCODING;
|
return SUN_JNU_ENCODING;
|
||||||
@ -287,10 +233,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code java.locale.useOldISOCodes} system property}
|
* {@return the {@code java.locale.useOldISOCodes} system property}
|
||||||
*
|
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. The caller of this method should take care to ensure
|
|
||||||
* that the returned property is not made accessible to untrusted code.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String javaLocaleUseOldISOCodes() {
|
public static String javaLocaleUseOldISOCodes() {
|
||||||
return JAVA_LOCALE_USE_OLD_ISO_CODES;
|
return JAVA_LOCALE_USE_OLD_ISO_CODES;
|
||||||
@ -298,8 +240,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code os.name} system property}
|
* {@return the {@code os.name} system property}
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. This property is not considered security sensitive.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String osName() {
|
public static String osName() {
|
||||||
return OS_NAME;
|
return OS_NAME;
|
||||||
@ -307,8 +247,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code os.arch} system property}
|
* {@return the {@code os.arch} system property}
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. This property is not considered security sensitive.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String osArch() {
|
public static String osArch() {
|
||||||
return OS_ARCH;
|
return OS_ARCH;
|
||||||
@ -316,8 +254,6 @@ public final class StaticProperty {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return the {@code os.version} system property}
|
* {@return the {@code os.version} system property}
|
||||||
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
|
|
||||||
* in this method. This property is not considered security sensitive.</strong>
|
|
||||||
*/
|
*/
|
||||||
public static String osVersion() {
|
public static String osVersion() {
|
||||||
return OS_VERSION;
|
return OS_VERSION;
|
||||||
|
@ -725,11 +725,7 @@ public class RandomSupport {
|
|||||||
|
|
||||||
// The following decides which of two strategies initialSeed() will use.
|
// The following decides which of two strategies initialSeed() will use.
|
||||||
private static boolean secureRandomSeedRequested() {
|
private static boolean secureRandomSeedRequested() {
|
||||||
@SuppressWarnings("removal")
|
return Boolean.getBoolean("java.util.secureRandomSeed");
|
||||||
String pp = java.security.AccessController.doPrivileged(
|
|
||||||
new sun.security.action.GetPropertyAction(
|
|
||||||
"java.util.secureRandomSeed"));
|
|
||||||
return (pp != null && pp.equalsIgnoreCase("true"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean useSecureRandomSeed = secureRandomSeedRequested();
|
private static final boolean useSecureRandomSeed = secureRandomSeedRequested();
|
||||||
|
Loading…
Reference in New Issue
Block a user