mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8066709: Make some JDK system properties read only
Reviewed-by: lancea, sundar, bchristi, weijun, mchung, alanb, mullan
This commit is contained in:
parent
cad47f4a03
commit
4098f2560a
25 changed files with 215 additions and 46 deletions
|
@ -59,6 +59,7 @@ import java.util.function.Supplier;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import jdk.internal.module.ModuleBootstrap;
|
||||
import jdk.internal.module.ServicesCatalog;
|
||||
import jdk.internal.reflect.CallerSensitive;
|
||||
|
@ -669,7 +670,16 @@ public final class System {
|
|||
* {@code getProperties} operation, it may choose to permit the
|
||||
* {@link #getProperty(String)} operation.
|
||||
*
|
||||
* @implNote In addition to the standard system properties, the system
|
||||
* @apiNote
|
||||
* <strong>Changing a standard system property may have unpredictable results
|
||||
* unless otherwise specified.</strong>
|
||||
* Property values may be cached during initialization or on first use.
|
||||
* Setting a standard property after initialization using {@link #getProperties()},
|
||||
* {@link #setProperties(Properties)}, {@link #setProperty(String, String)}, or
|
||||
* {@link #clearProperty(String)} may not have the desired effect.
|
||||
*
|
||||
* @implNote
|
||||
* In addition to the standard system properties, the system
|
||||
* properties may include the following keys:
|
||||
* <table class="striped">
|
||||
* <caption style="display:none">Shows property keys and associated values</caption>
|
||||
|
@ -736,6 +746,11 @@ public final class System {
|
|||
* {@code null}, then the current set of system properties is
|
||||
* forgotten.
|
||||
*
|
||||
* @apiNote
|
||||
* <strong>Changing a standard system property may have unpredictable results
|
||||
* unless otherwise specified</strong>.
|
||||
* See {@linkplain #getProperties getProperties} for details.
|
||||
*
|
||||
* @param props the new system properties.
|
||||
* @throws SecurityException if a security manager exists and its
|
||||
* {@code checkPropertiesAccess} method doesn't allow access
|
||||
|
@ -768,6 +783,11 @@ public final class System {
|
|||
* properties is first created and initialized in the same manner as
|
||||
* for the {@code getProperties} method.
|
||||
*
|
||||
* @apiNote
|
||||
* <strong>Changing a standard system property may have unpredictable results
|
||||
* unless otherwise specified</strong>.
|
||||
* See {@linkplain #getProperties getProperties} for details.
|
||||
*
|
||||
* @param key the name of the system property.
|
||||
* @return the string value of the system property,
|
||||
* or {@code null} if there is no property with that key.
|
||||
|
@ -837,6 +857,11 @@ public final class System {
|
|||
* If no exception is thrown, the specified property is set to the given
|
||||
* value.
|
||||
*
|
||||
* @apiNote
|
||||
* <strong>Changing a standard system property may have unpredictable results
|
||||
* unless otherwise specified</strong>.
|
||||
* See {@linkplain #getProperties getProperties} for details.
|
||||
*
|
||||
* @param key the name of the system property.
|
||||
* @param value the value of the system property.
|
||||
* @return the previous value of the system property,
|
||||
|
@ -875,6 +900,11 @@ public final class System {
|
|||
* permission. This may result in a SecurityException being thrown.
|
||||
* If no exception is thrown, the specified property is removed.
|
||||
*
|
||||
* @apiNote
|
||||
* <strong>Changing a standard system property may have unpredictable results
|
||||
* unless otherwise specified</strong>.
|
||||
* See {@linkplain #getProperties getProperties} method for details.
|
||||
*
|
||||
* @param key the name of the system property to be removed.
|
||||
* @return the previous string value of the system property,
|
||||
* or {@code null} if there was no property with that key.
|
||||
|
@ -1927,6 +1957,7 @@ public final class System {
|
|||
VM.saveAndRemoveProperties(props);
|
||||
|
||||
lineSeparator = props.getProperty("line.separator");
|
||||
StaticProperty.javaHome(); // Load StaticProperty to cache the property values
|
||||
VersionProps.init();
|
||||
|
||||
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
|
||||
|
|
|
@ -30,10 +30,11 @@ import java.io.BufferedOutputStream;
|
|||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.net.SocksProxy;
|
||||
import sun.net.spi.DefaultProxySelector;
|
||||
import sun.net.www.ParseUtil;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
/* import org.ietf.jgss.*; */
|
||||
|
||||
/**
|
||||
|
@ -178,7 +179,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
|
|||
userName = pw.getUserName();
|
||||
password = new String(pw.getPassword());
|
||||
} else {
|
||||
userName = GetPropertyAction.privilegedGetProperty("user.name");
|
||||
userName = StaticProperty.userName();
|
||||
}
|
||||
if (userName == null)
|
||||
return false;
|
||||
|
@ -1088,7 +1089,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
|
|||
userName = System.getProperty("user.name");
|
||||
} catch (SecurityException se) { /* swallow Exception */ }
|
||||
} else {
|
||||
userName = GetPropertyAction.privilegedGetProperty("user.name");
|
||||
userName = StaticProperty.userName();
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.io.*;
|
|||
import java.net.URL;
|
||||
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.util.Debug;
|
||||
import sun.security.util.PropertyExpander;
|
||||
|
||||
|
@ -214,7 +215,7 @@ public final class Security {
|
|||
// maybe check for a system property which will specify where to
|
||||
// look. Someday.
|
||||
String sep = File.separator;
|
||||
return new File(System.getProperty("java.home") + sep + "conf" + sep +
|
||||
return new File(StaticProperty.javaHome() + sep + "conf" + sep +
|
||||
"security" + sep + filename);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,19 +61,19 @@
|
|||
*/
|
||||
package java.time.zone;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -106,7 +106,7 @@ final class TzdbZoneRulesProvider extends ZoneRulesProvider {
|
|||
*/
|
||||
public TzdbZoneRulesProvider() {
|
||||
try {
|
||||
String libDir = System.getProperty("java.home") + File.separator + "lib";
|
||||
String libDir = StaticProperty.javaHome() + File.separator + "lib";
|
||||
try (DataInputStream dis = new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(
|
||||
new File(libDir, "tzdb.dat"))))) {
|
||||
|
|
|
@ -42,6 +42,8 @@ import java.util.regex.Pattern;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.spi.CurrencyNameProvider;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.util.locale.provider.CalendarDataUtility;
|
||||
import sun.util.locale.provider.LocaleServiceProviderPool;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
@ -236,7 +238,7 @@ public final class Currency implements Serializable {
|
|||
// look for the properties file for overrides
|
||||
String propsFile = System.getProperty("java.util.currency.data");
|
||||
if (propsFile == null) {
|
||||
propsFile = System.getProperty("java.home") + File.separator + "lib" +
|
||||
propsFile = StaticProperty.javaHome() + File.separator + "lib" +
|
||||
File.separator + "currency.properties";
|
||||
}
|
||||
try {
|
||||
|
@ -578,7 +580,7 @@ public final class Currency implements Serializable {
|
|||
|
||||
/**
|
||||
* Returns the 3 digit ISO 4217 numeric code of this currency as a {@code String}.
|
||||
* Unlike {@link getNumericCode()}, which returns the numeric code as {@code int},
|
||||
* Unlike {@link #getNumericCode()}, which returns the numeric code as {@code int},
|
||||
* this method always returns the numeric code as a 3 digit string.
|
||||
* e.g. a numeric value of 32 would be returned as "032",
|
||||
* and a numeric value of 6 would be returned as "006".
|
||||
|
|
|
@ -39,10 +39,9 @@
|
|||
package java.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Properties;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import sun.util.calendar.ZoneInfo;
|
||||
import sun.util.calendar.ZoneInfoFile;
|
||||
|
@ -667,7 +666,7 @@ public abstract class TimeZone implements Serializable, Cloneable {
|
|||
// if the time zone ID is not set (yet), perform the
|
||||
// platform to Java time zone ID mapping.
|
||||
if (zoneID == null || zoneID.isEmpty()) {
|
||||
String javaHome = props.getProperty("java.home");
|
||||
String javaHome = StaticProperty.javaHome();
|
||||
try {
|
||||
zoneID = getSystemTimeZoneID(javaHome);
|
||||
if (zoneID == null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue