diff -r 2e4903f83295 -r 95efb32d390b src/java.base/share/classes/java/lang/System.java --- a/src/java.base/share/classes/java/lang/System.java Wed Dec 12 15:26:49 2018 +0300 +++ b/src/java.base/share/classes/java/lang/System.java Wed Dec 12 13:28:50 2018 +0100 @@ -801,8 +801,9 @@ } if (props == null) { - props = SystemProps.initProperties(); - VersionProps.init(props); + Map tempProps = SystemProps.initProperties(); + VersionProps.init(tempProps); + props = createProperties(tempProps); } System.props = props; } @@ -1960,17 +1961,41 @@ } /** + * Create the Properties object from a map - masking out system properties + * that are not intended for public access. + */ + private static Properties createProperties(Map initialProps) { + Properties properties = new Properties(initialProps.size()); + for (var entry : initialProps.entrySet()) { + String prop = entry.getKey(); + switch (prop) { + // Do not add private system properties to the Properties + case "sun.nio.MaxDirectMemorySize": + case "sun.nio.PageAlignDirectMemory": + // used by java.lang.Integer.IntegerCache + case "java.lang.Integer.IntegerCache.high": + // used by sun.launcher.LauncherHelper + case "sun.java.launcher.diag": + // used by jdk.internal.loader.ClassLoaders + case "jdk.boot.class.path.append": + break; + default: + properties.put(prop, entry.getValue()); + } + } + return properties; + } + + /** * Initialize the system class. Called after thread initialization. */ private static void initPhase1() { - // VM might invoke JNU_NewStringPlatform() to set those encoding // sensitive properties (user.home, user.name, boot.class.path, etc.) // during "props" initialization. // The charset is initialized in System.c and does not depend on the Properties. - props = SystemProps.initProperties(); - VersionProps.init(props); - StaticProperty.javaHome(); // Load StaticProperty to cache the property values + Map tempProps = SystemProps.initProperties(); + VersionProps.init(tempProps); // There are certain system configurations that may be controlled by // VM options such as the maximum amount of direct memory and @@ -1978,15 +2003,14 @@ // of autoboxing. Typically, the library will obtain these values // from the properties set by the VM. If the properties are for // internal implementation use only, these properties should be - // removed from the system properties. - // - // See java.lang.Integer.IntegerCache and the - // VM.saveAndRemoveProperties method for example. + // masked from the system properties. // // Save a private copy of the system properties object that - // can only be accessed by the internal implementation. Remove - // certain system properties that are not intended for public access. - VM.saveAndRemoveProperties(props); + // can only be accessed by the internal implementation. + VM.saveProperties(tempProps); + props = createProperties(tempProps); + + StaticProperty.javaHome(); // Load StaticProperty to cache the property values lineSeparator = props.getProperty("line.separator");