src/share/classes/java/lang/System.java

Print this page
rev 9156 : 8022854: System.setProperties(null) causes implementation private properties to reappear
Reviewed-by: duke

*** 655,666 **** * <code>checkPropertiesAccess</code> method is called with no * arguments. This may result in a security exception. * <p> * The argument becomes the current set of system properties for use * by the {@link #getProperty(String)} method. If the argument is ! * <code>null</code>, then the current set of system properties is ! * forgotten. * * @param props the new system properties. * @exception SecurityException if a security manager exists and its * <code>checkPropertiesAccess</code> method doesn't allow access * to the system properties. --- 655,665 ---- * <code>checkPropertiesAccess</code> method is called with no * arguments. This may result in a security exception. * <p> * The argument becomes the current set of system properties for use * by the {@link #getProperty(String)} method. If the argument is ! * <code>null</code>, then the default system properties are reloaded. * * @param props the new system properties. * @exception SecurityException if a security manager exists and its * <code>checkPropertiesAccess</code> method doesn't allow access * to the system properties.
*** 672,686 **** public static void setProperties(Properties props) { SecurityManager sm = getSecurityManager(); if (sm != null) { sm.checkPropertiesAccess(); } ! if (props == null) { ! props = new Properties(); ! initProperties(props); ! } ! System.props = props; } /** * Gets the system property indicated by the specified key. * <p> --- 671,684 ---- public static void setProperties(Properties props) { SecurityManager sm = getSecurityManager(); if (sm != null) { sm.checkPropertiesAccess(); } ! ! System.props = (props != null) ! ? props ! : sun.misc.VM.getSanitizedSavedProperties(); } /** * Gets the system property indicated by the specified key. * <p>
*** 1160,1188 **** // very beginning of the initialization and all system properties to // be put into it directly. props = new Properties(); initProperties(props); // initialized by the VM // There are certain system configurations that may be controlled by // VM options such as the maximum amount of direct memory and // Integer cache size used to support the object identity semantics // 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 ! // sun.misc.VM.saveAndRemoveProperties method for example. // // 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. ! sun.misc.VM.saveAndRemoveProperties(props); lineSeparator = props.getProperty("line.separator"); - sun.misc.Version.init(); FileInputStream fdIn = new FileInputStream(FileDescriptor.in); FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out); FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err); setIn0(new BufferedInputStream(fdIn)); --- 1158,1188 ---- // very beginning of the initialization and all system properties to // be put into it directly. props = new Properties(); initProperties(props); // initialized by the VM + // requires System.setProperty() + sun.misc.Version.init(); + // There are certain system configurations that may be controlled by // VM options such as the maximum amount of direct memory and // Integer cache size used to support the object identity semantics // of autoboxing. Typically, the library will obtain these values ! // from the properties set by the VM. // // See java.lang.Integer.IntegerCache and the ! // sun.misc.VM.getSanitizedSavedProperties method for example. // // Save a private copy of the system properties object that ! // can only be accessed by the internal implementation. ! sun.misc.VM.saveVMSystemProperties(props); + // Initialize the public system properties without certain properties + // that are intended for internal implementation use only. + props = sun.misc.VM.getSanitizedSavedProperties(); lineSeparator = props.getProperty("line.separator"); FileInputStream fdIn = new FileInputStream(FileDescriptor.in); FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out); FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err); setIn0(new BufferedInputStream(fdIn));