/* * Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ package java.lang;
/** * The {@code System} class contains several useful class fields * and methods. It cannot be instantiated. * * Among the facilities provided by the {@code System} class * are standard input, standard output, and error output streams; * access to externally defined properties and environment * variables; a means of loading files and libraries; and a utility * method for quickly copying a portion of an array. * * @since 1.0
*/ publicfinalclass System { /* Register the natives via the static initializer. * * The VM will invoke the initPhase1 method to complete the initialization * of this class separate from <clinit>.
*/ privatestaticnativevoid registerNatives(); static {
registerNatives();
}
/** Don't let anyone instantiate this class */ private System() {
}
/** * The "standard" input stream. This stream is already * open and ready to supply input data. Typically this stream * corresponds to keyboard input or another input source specified by * the host environment or user. In case this stream is wrapped * in a {@link java.io.InputStreamReader}, {@link Console#charset()} * should be used for the charset, or consider using * {@link Console#reader()}. * * @see Console#charset() * @see Console#reader()
*/ publicstaticfinal InputStream in = null;
/** * The "standard" output stream. This stream is already * open and ready to accept output data. Typically this stream * corresponds to display output or another output destination * specified by the host environment or user. The encoding used * in the conversion from characters to bytes is equivalent to * {@link Console#charset()} if the {@code Console} exists, * <a href="#stdout.encoding">stdout.encoding</a> otherwise. * <p> * For simple stand-alone Java applications, a typical way to write * a line of output data is: * <blockquote><pre> * System.out.println(data) * </pre></blockquote> * <p> * See the {@code println} methods in class {@code PrintStream}. * * @see java.io.PrintStream#println() * @see java.io.PrintStream#println(boolean) * @see java.io.PrintStream#println(char) * @see java.io.PrintStream#println(char[]) * @see java.io.PrintStream#println(double) * @see java.io.PrintStream#println(float) * @see java.io.PrintStream#println(int) * @see java.io.PrintStream#println(long) * @see java.io.PrintStream#println(java.lang.Object) * @see java.io.PrintStream#println(java.lang.String) * @see Console#charset() * @see <a href="#stdout.encoding">stdout.encoding</a>
*/ publicstaticfinal PrintStream out = null;
/** * The "standard" error output stream. This stream is already * open and ready to accept output data. * <p> * Typically this stream corresponds to display output or another * output destination specified by the host environment or user. By * convention, this output stream is used to display error messages * or other information that should come to the immediate attention * of a user even if the principal output stream, the value of the * variable {@code out}, has been redirected to a file or other * destination that is typically not continuously monitored. * The encoding used in the conversion from characters to bytes is * equivalent to {@link Console#charset()} if the {@code Console} * exists, <a href="#stderr.encoding">stderr.encoding</a> otherwise. * * @see Console#charset() * @see <a href="#stderr.encoding">stderr.encoding</a>
*/ publicstaticfinal PrintStream err = null;
// Holder for the initial value of `in`, set within `initPhase1()`. privatestatic InputStream initialIn;
// indicates if a security manager is possible privatestaticfinalint NEVER = 1; privatestaticfinalint MAYBE = 2; privatestatic @Stable int allowSecurityManager;
// current security manager
@SuppressWarnings("removal") privatestaticvolatile SecurityManager security; // read by VM
// `sun.jnu.encoding` if it is not supported. Otherwise null. // It is initialized in `initPhase1()` before any charset providers // are initialized. privatestatic String notSupportedJnuEncoding;
// return true if a security manager is allowed privatestaticboolean allowSecurityManager() { return (allowSecurityManager != NEVER);
}
/** * Reassigns the "standard" input stream. * * First, if there is a security manager, its {@code checkPermission} * method is called with a {@code RuntimePermission("setIO")} permission * to see if it's ok to reassign the "standard" input stream. * * @param in the new standard input stream. * * @throws SecurityException * if a security manager exists and its * {@code checkPermission} method doesn't allow * reassigning of the standard input stream. * * @see SecurityManager#checkPermission * @see java.lang.RuntimePermission * * @since 1.1
*/ publicstaticvoid setIn(InputStream in) {
checkIO();
setIn0(in);
}
/** * Reassigns the "standard" output stream. * * First, if there is a security manager, its {@code checkPermission} * method is called with a {@code RuntimePermission("setIO")} permission * to see if it's ok to reassign the "standard" output stream. * * @param out the new standard output stream * * @throws SecurityException * if a security manager exists and its * {@code checkPermission} method doesn't allow * reassigning of the standard output stream. * * @see SecurityManager#checkPermission * @see java.lang.RuntimePermission * * @since 1.1
*/ publicstaticvoid setOut(PrintStream out) {
checkIO();
setOut0(out);
}
/** * Reassigns the "standard" error output stream. * * First, if there is a security manager, its {@code checkPermission} * method is called with a {@code RuntimePermission("setIO")} permission * to see if it's ok to reassign the "standard" error output stream. * * @param err the new standard error output stream. * * @throws SecurityException * if a security manager exists and its * {@code checkPermission} method doesn't allow * reassigning of the standard error output stream. * * @see SecurityManager#checkPermission * @see java.lang.RuntimePermission * * @since 1.1
*/ publicstaticvoid setErr(PrintStream err) {
checkIO();
setErr0(err);
}
privatestaticvolatile Console cons;
/** * Returns the unique {@link java.io.Console Console} object associated * with the current Java virtual machine, if any. * * @return The system console, if any, otherwise {@code null}. * * @since 1.6
*/ publicstatic Console console() {
Console c; if ((c = cons) == null) { synchronized (System.class) { if ((c = cons) == null) {
cons = c = SharedSecrets.getJavaIOAccess().console();
}
}
} return c;
}
/** * Returns the channel inherited from the entity that created this * Java virtual machine. * * This method returns the channel obtained by invoking the * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel * inheritedChannel} method of the system-wide default * {@link java.nio.channels.spi.SelectorProvider} object. * * <p> In addition to the network-oriented channels described in * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel * inheritedChannel}, this method may return other kinds of * channels in the future. * * @return The inherited channel, if any, otherwise {@code null}. * * @throws IOException * If an I/O error occurs * * @throws SecurityException * If a security manager is present and it does not * permit access to the channel. * * @since 1.5
*/ publicstatic Channel inheritedChannel() throws IOException { return SelectorProvider.provider().inheritedChannel();
}
privatestaticvoid checkIO() {
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPermission(new RuntimePermission("setIO"));
}
}
privatestaticclass CallersHolder { // Remember callers of setSecurityManager() here so that warning // is only printed once for each different caller staticfinal Map<Class<?>, Boolean> callers
= Collections.synchronizedMap(new WeakHashMap<>());
}
/** * Sets the system-wide security manager. * * If there is a security manager already installed, this method first * calls the security manager's {@code checkPermission} method * with a {@code RuntimePermission("setSecurityManager")} * permission to ensure it's ok to replace the existing * security manager. * This may result in throwing a {@code SecurityException}. * * <p> Otherwise, the argument is established as the current * security manager. If the argument is {@code null} and no * security manager has been established, then no action is taken and * the method simply returns. * * @implNote In the JDK implementation, if the Java virtual machine is * started with the system property {@code java.security.manager} not set or set to * the special token "{@code disallow}" then the {@code setSecurityManager} * method cannot be used to set a security manager. See the following * <a href="SecurityManager.html#set-security-manager">section of the * {@code SecurityManager} class specification</a> for more details. * * @param sm the security manager or {@code null} * @throws SecurityException * if the security manager has already been set and its {@code * checkPermission} method doesn't allow it to be replaced * @throws UnsupportedOperationException * if {@code sm} is non-null and a security manager is not allowed * to be set dynamically * @see #getSecurityManager * @see SecurityManager#checkPermission * @see java.lang.RuntimePermission * @deprecated This method is only useful in conjunction with * {@linkplain SecurityManager the Security Manager}, which is * deprecated and subject to removal in a future release. * Consequently, this method is also deprecated and subject to * removal. There is no replacement for the Security Manager or this * method.
*/
@Deprecated(since="17", forRemoval=true)
@CallerSensitive publicstaticvoid setSecurityManager(@SuppressWarnings("removal") SecurityManager sm) { if (allowSecurityManager()) { var callerClass = Reflection.getCallerClass(); if (CallersHolder.callers.putIfAbsent(callerClass, true) == null) {
URL url = codeSource(callerClass); final String source; if (url == null) {
source = callerClass.getName();
} else {
source = callerClass.getName() + " (" + url + ")";
}
initialErrStream.printf("""
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by %s
WARNING: Please consider reporting this to the maintainers of %s
WARNING: System::setSecurityManager will be removed in a future release """, source, callerClass.getName());
}
implSetSecurityManager(sm);
} else { // security manager not allowed if (sm != null) { thrownew UnsupportedOperationException( "The Security Manager is deprecated and will be removed in a future release");
}
}
}
privatestaticvoid implSetSecurityManager(@SuppressWarnings("removal") SecurityManager sm) { if (security == null) { // ensure image reader is initialized
Object.class.getResource("java/lang/ANY"); // ensure the default file system is initialized
DefaultFileSystemProvider.theFileSystem();
} if (sm != null) { try { // pre-populates the SecurityManager.packageAccess cache // to avoid recursive permission checking issues with custom // SecurityManager implementations
sm.checkPackageAccess("java.lang");
} catch (Exception e) { // no-op
}
}
setSecurityManager0(sm);
}
@SuppressWarnings("removal") privatestaticsynchronized void setSecurityManager0(final SecurityManager s) {
SecurityManager sm = getSecurityManager(); if (sm != null) { // ask the currently installed security manager if we // can replace it.
sm.checkPermission(new RuntimePermission("setSecurityManager"));
}
if ((s != null) && (s.getClass().getClassLoader() != null)) { // New security manager class is not on bootstrap classpath. // Force policy to get initialized before we install the new // security manager, in order to prevent infinite loops when // trying to initialize the policy (which usually involves // accessing some security and/or system properties, which in turn // calls the installed security manager's checkPermission method // which will loop infinitely if there is a non-system class // (in this case: the new security manager class) on the stack).
AccessController.doPrivileged(new PrivilegedAction<>() { public Object run() {
s.getClass().getProtectionDomain().implies
(SecurityConstants.ALL_PERMISSION); returnnull;
}
});
}
security = s;
}
/** * Gets the system-wide security manager. * * @return if a security manager has already been established for the * current application, then that security manager is returned; * otherwise, {@code null} is returned. * @see #setSecurityManager * @deprecated This method is only useful in conjunction with * {@linkplain SecurityManager the Security Manager}, which is * deprecated and subject to removal in a future release. * Consequently, this method is also deprecated and subject to * removal. There is no replacement for the Security Manager or this * method.
*/
@SuppressWarnings("removal")
@Deprecated(since="17", forRemoval=true) publicstatic SecurityManager getSecurityManager() { if (allowSecurityManager()) { return security;
} else { returnnull;
}
}
/** * Returns the current time in milliseconds. Note that * while the unit of time of the return value is a millisecond, * the granularity of the value depends on the underlying * operating system and may be larger. For example, many * operating systems measure time in units of tens of * milliseconds. * * <p> See the description of the class {@code Date} for * a discussion of slight discrepancies that may arise between * "computer time" and coordinated universal time (UTC). * * @return the difference, measured in milliseconds, between * the current time and midnight, January 1, 1970 UTC. * @see java.util.Date
*/
@IntrinsicCandidate publicstaticnativelong currentTimeMillis();
/** * Returns the current value of the running Java Virtual Machine's * high-resolution time source, in nanoseconds. * * This method can only be used to measure elapsed time and is * not related to any other notion of system or wall-clock time. * The value returned represents nanoseconds since some fixed but * arbitrary <i>origin</i> time (perhaps in the future, so values * may be negative). The same origin is used by all invocations of * this method in an instance of a Java virtual machine; other * virtual machine instances are likely to use a different origin. * * <p>This method provides nanosecond precision, but not necessarily * nanosecond resolution (that is, how frequently the value changes) * - no guarantees are made except that the resolution is at least as * good as that of {@link #currentTimeMillis()}. * * <p>Differences in successive calls that span greater than * approximately 292 years (2<sup>63</sup> nanoseconds) will not * correctly compute elapsed time due to numerical overflow. * * <p>The values returned by this method become meaningful only when * the difference between two such values, obtained within the same * instance of a Java virtual machine, is computed. * * <p>For example, to measure how long some code takes to execute: * <pre> {@code * long startTime = System.nanoTime(); * // ... the code being measured ... * long elapsedNanos = System.nanoTime() - startTime;}</pre> * * <p>To compare elapsed time against a timeout, use <pre> {@code * if (System.nanoTime() - startTime >= timeoutNanos) ...}</pre> * instead of <pre> {@code * if (System.nanoTime() >= startTime + timeoutNanos) ...}</pre> * because of the possibility of numerical overflow. * * @return the current value of the running Java Virtual Machine's * high-resolution time source, in nanoseconds * @since 1.5
*/
@IntrinsicCandidate publicstaticnativelong nanoTime();
/** * Copies an array from the specified source array, beginning at the * specified position, to the specified position of the destination array. * A subsequence of array components are copied from the source * array referenced by {@code src} to the destination array * referenced by {@code dest}. The number of components copied is * equal to the {@code length} argument. The components at * positions {@code srcPos} through * {@code srcPos+length-1} in the source array are copied into * positions {@code destPos} through * {@code destPos+length-1}, respectively, of the destination * array. * <p> * If the {@code src} and {@code dest} arguments refer to the * same array object, then the copying is performed as if the * components at positions {@code srcPos} through * {@code srcPos+length-1} were first copied to a temporary * array with {@code length} components and then the contents of * the temporary array were copied into positions * {@code destPos} through {@code destPos+length-1} of the * destination array. * <p> * If {@code dest} is {@code null}, then a * {@code NullPointerException} is thrown. * <p> * If {@code src} is {@code null}, then a * {@code NullPointerException} is thrown and the destination * array is not modified. * <p> * Otherwise, if any of the following is true, an * {@code ArrayStoreException} is thrown and the destination is * not modified: * <ul> * <li>The {@code src} argument refers to an object that is not an * array. * <li>The {@code dest} argument refers to an object that is not an * array. * <li>The {@code src} argument and {@code dest} argument refer * to arrays whose component types are different primitive types. * <li>The {@code src} argument refers to an array with a primitive * component type and the {@code dest} argument refers to an array * with a reference component type. * <li>The {@code src} argument refers to an array with a reference * component type and the {@code dest} argument refers to an array * with a primitive component type. * </ul> * <p> * Otherwise, if any of the following is true, an * {@code IndexOutOfBoundsException} is * thrown and the destination is not modified: * <ul> * <li>The {@code srcPos} argument is negative. * <li>The {@code destPos} argument is negative. * <li>The {@code length} argument is negative. * <li>{@code srcPos+length} is greater than * {@code src.length}, the length of the source array. * <li>{@code destPos+length} is greater than * {@code dest.length}, the length of the destination array. * </ul> * <p> * Otherwise, if any actual component of the source array from * position {@code srcPos} through * {@code srcPos+length-1} cannot be converted to the component * type of the destination array by assignment conversion, an * {@code ArrayStoreException} is thrown. In this case, let * <b><i>k</i></b> be the smallest nonnegative integer less than * length such that {@code src[srcPos+}<i>k</i>{@code ]} * cannot be converted to the component type of the destination * array; when the exception is thrown, source array components from * positions {@code srcPos} through * {@code srcPos+}<i>k</i>{@code -1} * will already have been copied to destination array positions * {@code destPos} through * {@code destPos+}<i>k</I>{@code -1} and no other * positions of the destination array will have been modified. * (Because of the restrictions already itemized, this * paragraph effectively applies only to the situation where both * arrays have component types that are reference types.) * * @param src the source array. * @param srcPos starting position in the source array. * @param dest the destination array. * @param destPos starting position in the destination data. * @param length the number of array elements to be copied. * @throws IndexOutOfBoundsException if copying would cause * access of data outside array bounds. * @throws ArrayStoreException if an element in the {@code src} * array could not be stored into the {@code dest} array * because of a type mismatch. * @throws NullPointerException if either {@code src} or * {@code dest} is {@code null}.
*/
@IntrinsicCandidate publicstaticnativevoid arraycopy(Object src, int srcPos,
Object dest, int destPos, int length);
/** * Returns the same hash code for the given object as * would be returned by the default method hashCode(), * whether or not the given object's class overrides * hashCode(). * The hash code for the null reference is zero. * * @param x object for which the hashCode is to be calculated * @return the hashCode * @since 1.1 * @see Object#hashCode * @see java.util.Objects#hashCode(Object)
*/
@IntrinsicCandidate publicstaticnativeint identityHashCode(Object x);
/** * System properties. * * See {@linkplain #getProperties getProperties} for details.
*/ privatestatic Properties props;
/** * Determines the current system properties. * * First, if there is a security manager, its * {@code checkPropertiesAccess} method is called with no * arguments. This may result in a security exception. * <p> * The current set of system properties for use by the * {@link #getProperty(String)} method is returned as a * {@code Properties} object. If there is no current set of * system properties, a set of system properties is first created and * initialized. This set of system properties includes a value * for each of the following keys unless the description of the associated * value indicates that the value is optional. * <table class="striped" style="text-align:left"> * <caption style="display:none">Shows property keys and associated values</caption> * <thead> * <tr><th scope="col">Key</th> * <th scope="col">Description of Associated Value</th></tr> * </thead> * <tbody> * <tr><th scope="row">{@systemProperty java.version}</th> * <td>Java Runtime Environment version, which may be interpreted * as a {@link Runtime.Version}</td></tr> * <tr><th scope="row">{@systemProperty java.version.date}</th> * <td>Java Runtime Environment version date, in ISO-8601 YYYY-MM-DD * format, which may be interpreted as a {@link * java.time.LocalDate}</td></tr> * <tr><th scope="row">{@systemProperty java.vendor}</th> * <td>Java Runtime Environment vendor</td></tr> * <tr><th scope="row">{@systemProperty java.vendor.url}</th> * <td>Java vendor URL</td></tr> * <tr><th scope="row">{@systemProperty java.vendor.version}</th> * <td>Java vendor version <em>(optional)</em> </td></tr> * <tr><th scope="row">{@systemProperty java.home}</th> * <td>Java installation directory</td></tr> * <tr><th scope="row">{@systemProperty java.vm.specification.version}</th> * <td>Java Virtual Machine specification version, whose value is the * {@linkplain Runtime.Version#feature feature} element of the * {@linkplain Runtime#version() runtime version}</td></tr> * <tr><th scope="row">{@systemProperty java.vm.specification.vendor}</th> * <td>Java Virtual Machine specification vendor</td></tr> * <tr><th scope="row">{@systemProperty java.vm.specification.name}</th> * <td>Java Virtual Machine specification name</td></tr> * <tr><th scope="row">{@systemProperty java.vm.version}</th> * <td>Java Virtual Machine implementation version which may be * interpreted as a {@link Runtime.Version}</td></tr> * <tr><th scope="row">{@systemProperty java.vm.vendor}</th> * <td>Java Virtual Machine implementation vendor</td></tr> * <tr><th scope="row">{@systemProperty java.vm.name}</th> * <td>Java Virtual Machine implementation name</td></tr> * <tr><th scope="row">{@systemProperty java.specification.version}</th> * <td>Java Runtime Environment specification version, whose value is * the {@linkplain Runtime.Version#feature feature} element of the * {@linkplain Runtime#version() runtime version}</td></tr> * <tr><th scope="row">{@systemProperty java.specification.maintenance.version}</th> * <td>Java Runtime Environment specification maintenance version, * may be interpreted as a positive integer <em>(optional, see below)</em></td></tr> * <tr><th scope="row">{@systemProperty java.specification.vendor}</th> * <td>Java Runtime Environment specification vendor</td></tr> * <tr><th scope="row">{@systemProperty java.specification.name}</th> * <td>Java Runtime Environment specification name</td></tr> * <tr><th scope="row">{@systemProperty java.class.version}</th> * <td>Java class format version number</td></tr> * <tr><th scope="row">{@systemProperty java.class.path}</th> * <td>Java class path (refer to * {@link ClassLoader#getSystemClassLoader()} for details)</td></tr> * <tr><th scope="row">{@systemProperty java.library.path}</th> * <td>List of paths to search when loading libraries</td></tr> * <tr><th scope="row">{@systemProperty java.io.tmpdir}</th> * <td>Default temp file path</td></tr> * <tr><th scope="row">{@systemProperty java.compiler}</th> * <td>Name of JIT compiler to use</td></tr> * <tr><th scope="row">{@systemProperty os.name}</th> * <td>Operating system name</td></tr> * <tr><th scope="row">{@systemProperty os.arch}</th> * <td>Operating system architecture</td></tr> * <tr><th scope="row">{@systemProperty os.version}</th> * <td>Operating system version</td></tr> * <tr><th scope="row">{@systemProperty file.separator}</th> * <td>File separator ("/" on UNIX)</td></tr> * <tr><th scope="row">{@systemProperty path.separator}</th> * <td>Path separator (":" on UNIX)</td></tr> * <tr><th scope="row">{@systemProperty line.separator}</th> * <td>Line separator ("\n" on UNIX)</td></tr> * <tr><th scope="row">{@systemProperty user.name}</th> * <td>User's account name</td></tr> * <tr><th scope="row">{@systemProperty user.home}</th> * <td>User's home directory</td></tr> * <tr><th scope="row">{@systemProperty user.dir}</th> * <td>User's current working directory</td></tr> * <tr><th scope="row">{@systemProperty native.encoding}</th> * <td>Character encoding name derived from the host environment and/or * the user's settings. Setting this system property has no effect.</td></tr> * <tr><th scope="row">{@systemProperty stdout.encoding}</th> * <td>Character encoding name for {@link System#out System.out}. * The Java runtime can be started with the system property set to {@code UTF-8}, * starting it with the property set to another value leads to undefined behavior. * <tr><th scope="row">{@systemProperty stderr.encoding}</th> * <td>Character encoding name for {@link System#err System.err}. * The Java runtime can be started with the system property set to {@code UTF-8}, * starting it with the property set to another value leads to undefined behavior. * </tbody> * </table> * <p> * The {@code java.specification.maintenance.version} property is * defined if the specification implemented by this runtime at the * time of its construction had undergone a <a * href="https://jcp.org/en/procedures/jcp2#3.6.4">maintenance * release</a>. When defined, its value identifies that * maintenance release. To indicate the first maintenance release * this property will have the value {@code "1"}, to indicate the * second maintenance release this property will have the value * {@code "2"}, and so on. * <p> * Multiple paths in a system property value are separated by the path * separator character of the platform. * <p> * Note that even if the security manager does not permit the * {@code getProperties} operation, it may choose to permit the * {@link #getProperty(String)} operation. * * @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> * <thead> * <tr><th scope="col">Key</th> * <th scope="col">Description of Associated Value</th></tr> * </thead> * <tbody> * <tr><th scope="row">{@systemProperty jdk.module.path}</th> * <td>The application module path</td></tr> * <tr><th scope="row">{@systemProperty jdk.module.upgrade.path}</th> * <td>The upgrade module path</td></tr> * <tr><th scope="row">{@systemProperty jdk.module.main}</th> * <td>The module name of the initial/main module</td></tr> * <tr><th scope="row">{@systemProperty jdk.module.main.class}</th> * <td>The main class name of the initial module</td></tr> * <tr><th scope="row">{@systemProperty file.encoding}</th> * <td>The name of the default charset, defaults to {@code UTF-8}. * The property may be set on the command line to the value * {@code UTF-8} or {@code COMPAT}. If set on the command line to * the value {@code COMPAT} then the value is replaced with the * value of the {@code native.encoding} property during startup. * Setting the property to a value other than {@code UTF-8} or * {@code COMPAT} leads to unspecified behavior. * </td></tr> * </tbody> * </table> * * @return the system properties * @throws SecurityException if a security manager exists and its * {@code checkPropertiesAccess} method doesn't allow access * to the system properties. * @see #setProperties * @see java.lang.SecurityException * @see java.lang.SecurityManager#checkPropertiesAccess() * @see java.util.Properties
*/ publicstatic Properties getProperties() {
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPropertiesAccess();
}
return props;
}
/** * Returns the system-dependent line separator string. It always * returns the same value - the initial value of the {@linkplain * #getProperty(String) system property} {@code line.separator}. * * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft * Windows systems it returns {@code "\r\n"}. * * @return the system-dependent line separator string * @since 1.7
*/ publicstatic String lineSeparator() { return lineSeparator;
}
privatestatic String lineSeparator;
/** * Sets the system properties to the {@code Properties} argument. * * First, if there is a security manager, its * {@code checkPropertiesAccess} 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}, 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 * to the system properties. * @see #getProperties * @see java.util.Properties * @see java.lang.SecurityException * @see java.lang.SecurityManager#checkPropertiesAccess()
*/ publicstaticvoid setProperties(Properties props) {
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPropertiesAccess();
}
/** * Gets the system property indicated by the specified key. * * First, if there is a security manager, its * {@code checkPropertyAccess} method is called with the key as * its argument. This may result in a SecurityException. * <p> * If there is no current set of system properties, a set of 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. * * @throws SecurityException if a security manager exists and its * {@code checkPropertyAccess} method doesn't allow * access to the specified system property. * @throws NullPointerException if {@code key} is {@code null}. * @throws IllegalArgumentException if {@code key} is empty. * @see #setProperty * @see java.lang.SecurityException * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) * @see java.lang.System#getProperties()
*/ publicstatic String getProperty(String key) {
checkKey(key);
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPropertyAccess(key);
}
return props.getProperty(key);
}
/** * Gets the system property indicated by the specified key. * * First, if there is a security manager, its * {@code checkPropertyAccess} method is called with the * {@code key} as its argument. * <p> * If there is no current set of system properties, a set of system * properties is first created and initialized in the same manner as * for the {@code getProperties} method. * * @param key the name of the system property. * @param def a default value. * @return the string value of the system property, * or the default value if there is no property with that key. * * @throws SecurityException if a security manager exists and its * {@code checkPropertyAccess} method doesn't allow * access to the specified system property. * @throws NullPointerException if {@code key} is {@code null}. * @throws IllegalArgumentException if {@code key} is empty. * @see #setProperty * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) * @see java.lang.System#getProperties()
*/ publicstatic String getProperty(String key, String def) {
checkKey(key);
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPropertyAccess(key);
}
return props.getProperty(key, def);
}
/** * Sets the system property indicated by the specified key. * * First, if a security manager exists, its * {@code SecurityManager.checkPermission} method * is called with a {@code PropertyPermission(key, "write")} * permission. This may result in a SecurityException being thrown. * 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, * or {@code null} if it did not have one. * * @throws SecurityException if a security manager exists and its * {@code checkPermission} method doesn't allow * setting of the specified property. * @throws NullPointerException if {@code key} or * {@code value} is {@code null}. * @throws IllegalArgumentException if {@code key} is empty. * @see #getProperty * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) * @see java.util.PropertyPermission * @see SecurityManager#checkPermission * @since 1.2
*/ publicstatic String setProperty(String key, String value) {
checkKey(key);
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPermission(new PropertyPermission(key,
SecurityConstants.PROPERTY_WRITE_ACTION));
}
return (String) props.setProperty(key, value);
}
/** * Removes the system property indicated by the specified key. * * First, if a security manager exists, its * {@code SecurityManager.checkPermission} method * is called with a {@code PropertyPermission(key, "write")} * 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. * * @throws SecurityException if a security manager exists and its * {@code checkPropertyAccess} method doesn't allow * access to the specified system property. * @throws NullPointerException if {@code key} is {@code null}. * @throws IllegalArgumentException if {@code key} is empty. * @see #getProperty * @see #setProperty * @see java.util.Properties * @see java.lang.SecurityException * @see java.lang.SecurityManager#checkPropertiesAccess() * @since 1.5
*/ publicstatic String clearProperty(String key) {
checkKey(key);
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPermission(new PropertyPermission(key, "write"));
}
return (String) props.remove(key);
}
privatestaticvoid checkKey(String key) { if (key == null) { thrownew NullPointerException("key can't be null");
} if (key.isEmpty()) { thrownew IllegalArgumentException("key can't be empty");
}
}
/** * Gets the value of the specified environment variable. An * environment variable is a system-dependent external named * value. * * <p>If a security manager exists, its * {@link SecurityManager#checkPermission checkPermission} * method is called with a * {@link RuntimePermission RuntimePermission("getenv."+name)} * permission. This may result in a {@link SecurityException} * being thrown. If no exception is thrown the value of the * variable {@code name} is returned. * * <p><a id="EnvironmentVSSystemProperties"><i>System * properties</i> and <i>environment variables</i></a> are both * conceptually mappings between names and values. Both * mechanisms can be used to pass user-defined information to a * Java process. Environment variables have a more global effect, * because they are visible to all descendants of the process * which defines them, not just the immediate Java subprocess. * They can have subtly different semantics, such as case * insensitivity, on different operating systems. For these * reasons, environment variables are more likely to have * unintended side effects. It is best to use system properties * where possible. Environment variables should be used when a * global effect is desired, or when an external system interface * requires an environment variable (such as {@code PATH}). * * <p>On UNIX systems the alphabetic case of {@code name} is * typically significant, while on Microsoft Windows systems it is * typically not. For example, the expression * {@code System.getenv("FOO").equals(System.getenv("foo"))} * is likely to be true on Microsoft Windows. * * @param name the name of the environment variable * @return the string value of the variable, or {@code null} * if the variable is not defined in the system environment * @throws NullPointerException if {@code name} is {@code null} * @throws SecurityException * if a security manager exists and its * {@link SecurityManager#checkPermission checkPermission} * method doesn't allow access to the environment variable * {@code name} * @see #getenv() * @see ProcessBuilder#environment()
*/ publicstatic String getenv(String name) {
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPermission(new RuntimePermission("getenv."+name));
}
return ProcessEnvironment.getenv(name);
}
/** * Returns an unmodifiable string map view of the current system environment. * The environment is a system-dependent mapping from names to * values which is passed from parent to child processes. * * <p>If the system does not support environment variables, an * empty map is returned. * * <p>The returned map will never contain null keys or values. * Attempting to query the presence of a null key or value will * throw a {@link NullPointerException}. Attempting to query * the presence of a key or value which is not of type * {@link String} will throw a {@link ClassCastException}. * * <p>The returned map and its collection views may not obey the * general contract of the {@link Object#equals} and * {@link Object#hashCode} methods. * * <p>The returned map is typically case-sensitive on all platforms. * * <p>If a security manager exists, its * {@link SecurityManager#checkPermission checkPermission} * method is called with a * {@link RuntimePermission RuntimePermission("getenv.*")} permission. * This may result in a {@link SecurityException} being thrown. * * <p>When passing information to a Java subprocess, * <a href=#EnvironmentVSSystemProperties>system properties</a> * are generally preferred over environment variables. * * @return the environment as a map of variable names to values * @throws SecurityException * if a security manager exists and its * {@link SecurityManager#checkPermission checkPermission} * method doesn't allow access to the process environment * @see #getenv(String) * @see ProcessBuilder#environment() * @since 1.5
*/ publicstatic java.util.Map<String,String> getenv() {
@SuppressWarnings("removal")
SecurityManager sm = getSecurityManager(); if (sm != null) {
sm.checkPermission(new RuntimePermission("getenv.*"));
}
return ProcessEnvironment.getenv();
}
/** * {@code System.Logger} instances log messages that will be * routed to the underlying logging framework the {@link System.LoggerFinder * LoggerFinder} uses. * * {@code System.Logger} instances are typically obtained from * the {@link java.lang.System System} class, by calling * {@link java.lang.System#getLogger(java.lang.String) System.getLogger(loggerName)} * or {@link java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle) * System.getLogger(loggerName, bundle)}. * * @see java.lang.System#getLogger(java.lang.String) * @see java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle) * @see java.lang.System.LoggerFinder * * @since 9
*/ publicinterface Logger {
/** * System {@linkplain Logger loggers} levels. * * A level has a {@linkplain #getName() name} and {@linkplain * #getSeverity() severity}. * Level values are {@link #ALL}, {@link #TRACE}, {@link #DEBUG}, * {@link #INFO}, {@link #WARNING}, {@link #ERROR}, {@link #OFF}, * by order of increasing severity. * <br> * {@link #ALL} and {@link #OFF} * are simple markers with severities mapped respectively to * {@link java.lang.Integer#MIN_VALUE Integer.MIN_VALUE} and * {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}. * <p> * <b>Severity values and Mapping to {@code java.util.logging.Level}.</b> * <p> * {@linkplain System.Logger.Level System logger levels} are mapped to * {@linkplain java.logging/java.util.logging.Level java.util.logging levels} * of corresponding severity. * <br>The mapping is as follows: * <br><br> * <table class="striped"> * <caption>System.Logger Severity Level Mapping</caption> * <thead> * <tr><th scope="col">System.Logger Levels</th> * <th scope="col">java.util.logging Levels</th> * </thead> * <tbody> * <tr><th scope="row">{@link Logger.Level#ALL ALL}</th> * <td>{@link java.logging/java.util.logging.Level#ALL ALL}</td> * <tr><th scope="row">{@link Logger.Level#TRACE TRACE}</th> * <td>{@link java.logging/java.util.logging.Level#FINER FINER}</td> * <tr><th scope="row">{@link Logger.Level#DEBUG DEBUG}</th> * <td>{@link java.logging/java.util.logging.Level#FINE FINE}</td> * <tr><th scope="row">{@link Logger.Level#INFO INFO}</th> * <td>{@link java.logging/java.util.logging.Level#INFO INFO}</td> * <tr><th scope="row">{@link Logger.Level#WARNING WARNING}</th> * <td>{@link java.logging/java.util.logging.Level#WARNING WARNING}</td> * <tr><th scope="row">{@link Logger.Level#ERROR ERROR}</th> * <td>{@link java.logging/java.util.logging.Level#SEVERE SEVERE}</td> * <tr><th scope="row">{@link Logger.Level#OFF OFF}</th> * <td>{@link java.logging/java.util.logging.Level#OFF OFF}</td> * </tbody> * </table> * * @since 9 * * @see java.lang.System.LoggerFinder * @see java.lang.System.Logger
*/
@SuppressWarnings("doclint:reference") // cross-module links publicenum Level {
// for convenience, we're reusing java.util.logging.Level int values // the mapping logic in sun.util.logging.PlatformLogger depends // on this. /** * A marker to indicate that all levels are enabled. * This level {@linkplain #getSeverity() severity} is * {@link Integer#MIN_VALUE}.
*/
ALL(Integer.MIN_VALUE), // typically mapped to/from j.u.l.Level.ALL /** * {@code TRACE} level: usually used to log diagnostic information. * This level {@linkplain #getSeverity() severity} is * {@code 400}.
*/
TRACE(400), // typically mapped to/from j.u.l.Level.FINER /** * {@code DEBUG} level: usually used to log debug information traces. * This level {@linkplain #getSeverity() severity} is * {@code 500}.
*/
DEBUG(500), // typically mapped to/from j.u.l.Level.FINEST/FINE/CONFIG /** * {@code INFO} level: usually used to log information messages. * This level {@linkplain #getSeverity() severity} is * {@code 800}.
*/
INFO(800), // typically mapped to/from j.u.l.Level.INFO /** * {@code WARNING} level: usually used to log warning messages. * This level {@linkplain #getSeverity() severity} is * {@code 900}.
*/
WARNING(900), // typically mapped to/from j.u.l.Level.WARNING /** * {@code ERROR} level: usually used to log error messages. * This level {@linkplain #getSeverity() severity} is * {@code 1000}.
*/
ERROR(1000), // typically mapped to/from j.u.l.Level.SEVERE /** * A marker to indicate that all levels are disabled. * This level {@linkplain #getSeverity() severity} is * {@link Integer#MAX_VALUE}.
*/
OFF(Integer.MAX_VALUE); // typically mapped to/from j.u.l.Level.OFF
/** * Returns the name of this level. * @return this level {@linkplain #name()}.
*/ publicfinal String getName() { return name();
}
/** * Returns the severity of this level. * A higher severity means a more severe condition. * @return this level severity.
*/ publicfinalint getSeverity() { return severity;
}
}
/** * Returns the name of this logger. * * @return the logger name.
*/ public String getName();
/** * Checks if a message of the given level would be logged by * this logger. * * @param level the log message level. * @return {@code true} if the given log message level is currently * being logged. * * @throws NullPointerException if {@code level} is {@code null}.
*/ publicboolean isLoggable(Level level);
/** * Logs a message. * * @implSpec The default implementation for this method calls * {@code this.log(level, (ResourceBundle)null, msg, (Object[])null);} * * @param level the log message level. * @param msg the string message (or a key in the message catalog, if * this logger is a {@link * LoggerFinder#getLocalizedLogger(java.lang.String, * java.util.ResourceBundle, java.lang.Module) localized logger}); * can be {@code null}. * * @throws NullPointerException if {@code level} is {@code null}.
*/ publicdefaultvoid log(Level level, String msg) {
log(level, (ResourceBundle) null, msg, (Object[]) null);
}
/** * Logs a lazily supplied message. * * If the logger is currently enabled for the given log message level * then a message is logged that is the result produced by the * given supplier function. Otherwise, the supplier is not operated on. * * @implSpec When logging is enabled for the given level, the default * implementation for this method calls * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), (Object[])null);} * * @param level the log message level. * @param msgSupplier a supplier function that produces a message. * * @throws NullPointerException if {@code level} is {@code null}, * or {@code msgSupplier} is {@code null}.
*/ publicdefaultvoid log(Level level, Supplier<String> msgSupplier) {
Objects.requireNonNull(msgSupplier); if (isLoggable(Objects.requireNonNull(level))) {
log(level, (ResourceBundle) null, msgSupplier.get(), (Object[]) null);
}
}
/** * Logs a message produced from the given object. * * If the logger is currently enabled for the given log message level then * a message is logged that, by default, is the result produced from * calling toString on the given object. * Otherwise, the object is not operated on. * * @implSpec When logging is enabled for the given level, the default * implementation for this method calls * {@code this.log(level, (ResourceBundle)null, obj.toString(), (Object[])null);} * * @param level the log message level. * @param obj the object to log. * * @throws NullPointerException if {@code level} is {@code null}, or * {@code obj} is {@code null}.
*/ publicdefaultvoid log(Level level, Object obj) {
Objects.requireNonNull(obj); if (isLoggable(Objects.requireNonNull(level))) { this.log(level, (ResourceBundle) null, obj.toString(), (Object[]) null);
}
}
/** * Logs a message associated with a given throwable. * * @implSpec The default implementation for this method calls * {@code this.log(level, (ResourceBundle)null, msg, thrown);} * * @param level the log message level. * @param msg the string message (or a key in the message catalog, if * this logger is a {@link * LoggerFinder#getLocalizedLogger(java.lang.String, * java.util.ResourceBundle, java.lang.Module) localized logger}); * can be {@code null}. * @param thrown a {@code Throwable} associated with the log message; * can be {@code null}. * * @throws NullPointerException if {@code level} is {@code null}.
*/ publicdefaultvoid log(Level level, String msg, Throwable thrown) { this.log(level, null, msg, thrown);
}
/** * Logs a lazily supplied message associated with a given throwable. * * If the logger is currently enabled for the given log message level * then a message is logged that is the result produced by the * given supplier function. Otherwise, the supplier is not operated on. * * @implSpec When logging is enabled for the given level, the default * implementation for this method calls * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), thrown);} * * @param level one of the log message level identifiers. * @param msgSupplier a supplier function that produces a message. * @param thrown a {@code Throwable} associated with log message; * can be {@code null}. * * @throws NullPointerException if {@code level} is {@code null}, or * {@code msgSupplier} is {@code null}.
*/ publicdefaultvoid log(Level level, Supplier<String> msgSupplier,
Throwable thrown) {
Objects.requireNonNull(msgSupplier); if (isLoggable(Objects.requireNonNull(level))) { this.log(level, null, msgSupplier.get(), thrown);
}
}
/** * Logs a message with an optional list of parameters. * * @implSpec The default implementation for this method calls * {@code this.log(level, (ResourceBundle)null, format, params);} * * @param level one of the log message level identifiers. * @param format the string message format in {@link * java.text.MessageFormat} format, (or a key in the message * catalog, if this logger is a {@link * LoggerFinder#getLocalizedLogger(java.lang.String, * java.util.ResourceBundle, java.lang.Module) localized logger}); * can be {@code null}. * @param params an optional list of parameters to the message (may be * none).
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.