785 * unless otherwise specified</strong>.
786 * See {@linkplain #getProperties getProperties} for details.
787 *
788 * @param props the new system properties.
789 * @throws SecurityException if a security manager exists and its
790 * {@code checkPropertiesAccess} method doesn't allow access
791 * to the system properties.
792 * @see #getProperties
793 * @see java.util.Properties
794 * @see java.lang.SecurityException
795 * @see java.lang.SecurityManager#checkPropertiesAccess()
796 */
797 public static void setProperties(Properties props) {
798 SecurityManager sm = getSecurityManager();
799 if (sm != null) {
800 sm.checkPropertiesAccess();
801 }
802 if (props == null) {
803 props = new Properties();
804 initProperties(props);
805 }
806 System.props = props;
807 }
808
809 /**
810 * Gets the system property indicated by the specified key.
811 *
812 * First, if there is a security manager, its
813 * {@code checkPropertyAccess} method is called with the key as
814 * its argument. This may result in a SecurityException.
815 * <p>
816 * If there is no current set of system properties, a set of system
817 * properties is first created and initialized in the same manner as
818 * for the {@code getProperties} method.
819 *
820 * @apiNote
821 * <strong>Changing a standard system property may have unpredictable results
822 * unless otherwise specified</strong>.
823 * See {@linkplain #getProperties getProperties} for details.
824 *
1956 log.println("Caused by: " + cause);
1957 }
1958 }
1959 }
1960
1961 /**
1962 * Initialize the system class. Called after thread initialization.
1963 */
1964 private static void initPhase1() {
1965
1966 // VM might invoke JNU_NewStringPlatform() to set those encoding
1967 // sensitive properties (user.home, user.name, boot.class.path, etc.)
1968 // during "props" initialization, in which it may need access, via
1969 // System.getProperty(), to the related system encoding property that
1970 // have been initialized (put into "props") at early stage of the
1971 // initialization. So make sure the "props" is available at the
1972 // very beginning of the initialization and all system properties to
1973 // be put into it directly.
1974 props = new Properties(84);
1975 initProperties(props); // initialized by the VM
1976
1977 // There are certain system configurations that may be controlled by
1978 // VM options such as the maximum amount of direct memory and
1979 // Integer cache size used to support the object identity semantics
1980 // of autoboxing. Typically, the library will obtain these values
1981 // from the properties set by the VM. If the properties are for
1982 // internal implementation use only, these properties should be
1983 // removed from the system properties.
1984 //
1985 // See java.lang.Integer.IntegerCache and the
1986 // VM.saveAndRemoveProperties method for example.
1987 //
1988 // Save a private copy of the system properties object that
1989 // can only be accessed by the internal implementation. Remove
1990 // certain system properties that are not intended for public access.
1991 VM.saveAndRemoveProperties(props);
1992
1993 lineSeparator = props.getProperty("line.separator");
1994 StaticProperty.javaHome(); // Load StaticProperty to cache the property values
1995 VersionProps.init();
1996
1997 FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
1998 FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
1999 FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
2000 setIn0(new BufferedInputStream(fdIn));
2001 setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
2002 setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
2003
2004 // Setup Java signal handlers for HUP, TERM, and INT (where available).
2005 Terminator.setup();
2006
2007 // Initialize any miscellaneous operating system settings that need to be
2008 // set for the class libraries. Currently this is no-op everywhere except
2009 // for Windows where the process-wide error mode is set before the java.io
2010 // classes are used.
2011 VM.initializeOSEnvironment();
2012
2013 // The main thread is not added to its thread group in the same
2014 // way as other threads; we must do it ourselves here.
2015 Thread current = Thread.currentThread();
|
785 * unless otherwise specified</strong>.
786 * See {@linkplain #getProperties getProperties} for details.
787 *
788 * @param props the new system properties.
789 * @throws SecurityException if a security manager exists and its
790 * {@code checkPropertiesAccess} method doesn't allow access
791 * to the system properties.
792 * @see #getProperties
793 * @see java.util.Properties
794 * @see java.lang.SecurityException
795 * @see java.lang.SecurityManager#checkPropertiesAccess()
796 */
797 public static void setProperties(Properties props) {
798 SecurityManager sm = getSecurityManager();
799 if (sm != null) {
800 sm.checkPropertiesAccess();
801 }
802 if (props == null) {
803 props = new Properties();
804 initProperties(props);
805 VersionProps.init(props);
806 }
807 System.props = props;
808 }
809
810 /**
811 * Gets the system property indicated by the specified key.
812 *
813 * First, if there is a security manager, its
814 * {@code checkPropertyAccess} method is called with the key as
815 * its argument. This may result in a SecurityException.
816 * <p>
817 * If there is no current set of system properties, a set of system
818 * properties is first created and initialized in the same manner as
819 * for the {@code getProperties} method.
820 *
821 * @apiNote
822 * <strong>Changing a standard system property may have unpredictable results
823 * unless otherwise specified</strong>.
824 * See {@linkplain #getProperties getProperties} for details.
825 *
1957 log.println("Caused by: " + cause);
1958 }
1959 }
1960 }
1961
1962 /**
1963 * Initialize the system class. Called after thread initialization.
1964 */
1965 private static void initPhase1() {
1966
1967 // VM might invoke JNU_NewStringPlatform() to set those encoding
1968 // sensitive properties (user.home, user.name, boot.class.path, etc.)
1969 // during "props" initialization, in which it may need access, via
1970 // System.getProperty(), to the related system encoding property that
1971 // have been initialized (put into "props") at early stage of the
1972 // initialization. So make sure the "props" is available at the
1973 // very beginning of the initialization and all system properties to
1974 // be put into it directly.
1975 props = new Properties(84);
1976 initProperties(props); // initialized by the VM
1977 VersionProps.init(props);
1978
1979 // There are certain system configurations that may be controlled by
1980 // VM options such as the maximum amount of direct memory and
1981 // Integer cache size used to support the object identity semantics
1982 // of autoboxing. Typically, the library will obtain these values
1983 // from the properties set by the VM. If the properties are for
1984 // internal implementation use only, these properties should be
1985 // removed from the system properties.
1986 //
1987 // See java.lang.Integer.IntegerCache and the
1988 // VM.saveAndRemoveProperties method for example.
1989 //
1990 // Save a private copy of the system properties object that
1991 // can only be accessed by the internal implementation. Remove
1992 // certain system properties that are not intended for public access.
1993 VM.saveAndRemoveProperties(props);
1994
1995 lineSeparator = props.getProperty("line.separator");
1996 StaticProperty.javaHome(); // Load StaticProperty to cache the property values
1997
1998 FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
1999 FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
2000 FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
2001 setIn0(new BufferedInputStream(fdIn));
2002 setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
2003 setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
2004
2005 // Setup Java signal handlers for HUP, TERM, and INT (where available).
2006 Terminator.setup();
2007
2008 // Initialize any miscellaneous operating system settings that need to be
2009 // set for the class libraries. Currently this is no-op everywhere except
2010 // for Windows where the process-wide error mode is set before the java.io
2011 // classes are used.
2012 VM.initializeOSEnvironment();
2013
2014 // The main thread is not added to its thread group in the same
2015 // way as other threads; we must do it ourselves here.
2016 Thread current = Thread.currentThread();
|