jdk/src/java.base/share/classes/java/lang/Runtime.java
author redestad
Mon, 01 Aug 2016 20:32:10 +0200
changeset 39889 2e82e1c36e90
parent 39766 745f165bedee
child 40793 fb8850791384
permissions -rw-r--r--
8162439: Runtime.Version.parse needs fast-path for major versions Reviewed-by: psandoz, sdrach, iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
     2
 * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    29
import java.math.BigInteger;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    30
import java.util.ArrayList;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    31
import java.util.regex.Matcher;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    32
import java.util.regex.Pattern;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    33
import java.util.stream.Collectors;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    34
import java.util.Collections;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    35
import java.util.List;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    36
import java.util.Optional;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.StringTokenizer;
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 34350
diff changeset
    38
import jdk.internal.reflect.CallerSensitive;
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 34350
diff changeset
    39
import jdk.internal.reflect.Reflection;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Every Java application has a single instance of class
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    43
 * {@code Runtime} that allows the application to interface with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the environment in which the application is running. The current
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    45
 * runtime can be obtained from the {@code getRuntime} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * An application cannot create its own instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see     java.lang.Runtime#getRuntime()
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
    51
 * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class Runtime {
34350
6beb09485bdd 8144210: Runtime.currentRuntime should be final
alanb
parents: 30042
diff changeset
    55
    private static final Runtime currentRuntime = new Runtime();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    57
    private static Version version;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
    58
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Returns the runtime object associated with the current Java application.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    61
     * Most of the methods of class {@code Runtime} are instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * methods and must be invoked with respect to the current runtime object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    64
     * @return  the {@code Runtime} object associated with the current
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *          Java application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static Runtime getRuntime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return currentRuntime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /** Don't let anyone else instantiate this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private Runtime() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Terminates the currently running Java virtual machine by initiating its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * shutdown sequence.  This method never returns normally.  The argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * serves as a status code; by convention, a nonzero status code indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * abnormal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <p> The virtual machine's shutdown sequence consists of two phases.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * the first phase all registered {@link #addShutdownHook shutdown hooks},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * if any, are started in some unspecified order and allowed to run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * concurrently until they finish.  In the second phase all uninvoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * finalizers are run if {@link #runFinalizersOnExit finalization-on-exit}
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    85
     * has been enabled.  Once this is done the virtual machine {@link #halt halts}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <p> If this method is invoked after the virtual machine has begun its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * shutdown sequence then if shutdown hooks are being run this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * block indefinitely.  If shutdown hooks have already been run and on-exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * finalization has been enabled then this method halts the virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * with the given status code if the status is nonzero; otherwise, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * blocks indefinitely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    94
     * <p> The {@link System#exit(int) System.exit} method is the
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 18776
diff changeset
    95
     * conventional and convenient means of invoking this method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param  status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *         Termination status.  By convention, a nonzero status code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *         indicates abnormal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @throws SecurityException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   102
     *         If a security manager is present and its
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   103
     *         {@link SecurityManager#checkExit checkExit} method does not permit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *         exiting with the specified status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see java.lang.SecurityManager#checkExit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see #addShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @see #removeShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see #runFinalizersOnExit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #halt(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public void exit(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            security.checkExit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        Shutdown.exit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Registers a new virtual-machine shutdown hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p> The Java virtual machine <i>shuts down</i> in response to two kinds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * of events:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *   <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
   129
     *   <li> The program <i>exits</i> normally, when the last non-daemon
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   130
     *   thread exits or when the {@link #exit exit} (equivalently,
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
   131
     *   {@link System#exit(int) System.exit}) method is invoked, or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
   133
     *   <li> The virtual machine is <i>terminated</i> in response to a
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   134
     *   user interrupt, such as typing {@code ^C}, or a system-wide event,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *   such as user logoff or system shutdown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *   </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <p> A <i>shutdown hook</i> is simply an initialized but unstarted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * thread.  When the virtual machine begins its shutdown sequence it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * start all registered shutdown hooks in some unspecified order and let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * them run concurrently.  When all the hooks have finished it will then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * run all uninvoked finalizers if finalization-on-exit has been enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Finally, the virtual machine will halt.  Note that daemon threads will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * continue to run during the shutdown sequence, as will non-daemon threads
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   146
     * if shutdown was initiated by invoking the {@link #exit exit} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <p> Once the shutdown sequence has begun it can be stopped only by
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   149
     * invoking the {@link #halt halt} method, which forcibly
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * terminates the virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <p> Once the shutdown sequence has begun it is impossible to register a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * new shutdown hook or de-register a previously-registered hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Attempting either of these operations will cause an
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   155
     * {@link IllegalStateException} to be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <p> Shutdown hooks run at a delicate time in the life cycle of a virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * machine and should therefore be coded defensively.  They should, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * particular, be written to be thread-safe and to avoid deadlocks insofar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * as possible.  They should also not rely blindly upon services that may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * have registered their own shutdown hooks and therefore may themselves in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * the process of shutting down.  Attempts to use other thread-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * services such as the AWT event-dispatch thread, for example, may lead to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * deadlocks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p> Shutdown hooks should also finish their work quickly.  When a
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   167
     * program invokes {@link #exit exit} the expectation is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * that the virtual machine will promptly shut down and exit.  When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * virtual machine is terminated due to user logoff or system shutdown the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * underlying operating system may only allow a fixed amount of time in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * which to shut down and exit.  It is therefore inadvisable to attempt any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * user interaction or to perform a long-running computation in a shutdown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <p> Uncaught exceptions are handled in shutdown hooks just as in any
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   176
     * other thread, by invoking the
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   177
     * {@link ThreadGroup#uncaughtException uncaughtException} method of the
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   178
     * thread's {@link ThreadGroup} object. The default implementation of this
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   179
     * method prints the exception's stack trace to {@link System#err} and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * terminates the thread; it does not cause the virtual machine to exit or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * halt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <p> In rare circumstances the virtual machine may <i>abort</i>, that is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * stop running without shutting down cleanly.  This occurs when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * virtual machine is terminated externally, for example with the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   186
     * {@code SIGKILL} signal on Unix or the {@code TerminateProcess} call on
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Microsoft Windows.  The virtual machine may also abort if a native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * method goes awry by, for example, corrupting internal data structures or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * attempting to access nonexistent memory.  If the virtual machine aborts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * then no guarantee can be made about whether or not any shutdown hooks
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 18776
diff changeset
   191
     * will be run.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param   hook
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   194
     *          An initialized but unstarted {@link Thread} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *          If the specified hook has already been registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *          or if it can be determined that the hook is already running or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *          has already been run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *          If the virtual machine is already in the process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *          of shutting down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *          If a security manager is present and it denies
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   207
     *          {@link RuntimePermission}("shutdownHooks")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @see #removeShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see #halt(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see #exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public void addShutdownHook(Thread hook) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            sm.checkPermission(new RuntimePermission("shutdownHooks"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        ApplicationShutdownHooks.add(hook);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   223
     * De-registers a previously-registered virtual-machine shutdown hook.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param hook the hook to remove
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   226
     * @return {@code true} if the specified hook had previously been
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   227
     * registered and was successfully de-registered, {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *          If the virtual machine is already in the process of shutting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *          down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *          If a security manager is present and it denies
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   236
     *          {@link RuntimePermission}("shutdownHooks")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see #addShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @see #exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public boolean removeShutdownHook(Thread hook) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            sm.checkPermission(new RuntimePermission("shutdownHooks"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return ApplicationShutdownHooks.remove(hook);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Forcibly terminates the currently running Java virtual machine.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * method never returns normally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <p> This method should be used with extreme caution.  Unlike the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   255
     * {@link #exit exit} method, this method does not cause shutdown
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * hooks to be started and does not run uninvoked finalizers if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * finalization-on-exit has been enabled.  If the shutdown sequence has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * already been initiated then this method does not wait for any running
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 18776
diff changeset
   259
     * shutdown hooks or finalizers to finish their work.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param  status
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   262
     *         Termination status. By convention, a nonzero status code
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   263
     *         indicates abnormal termination. If the {@link Runtime#exit exit}
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   264
     *         (equivalently, {@link System#exit(int) System.exit}) method
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   265
     *         has already been invoked then this status code
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   266
     *         will override the status code passed to that method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @throws SecurityException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   269
     *         If a security manager is present and its
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   270
     *         {@link SecurityManager#checkExit checkExit} method
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   271
     *         does not permit an exit with the specified status
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @see #exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @see #addShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @see #removeShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public void halt(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            sm.checkExit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        Shutdown.halt(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Enable or disable finalization on exit; doing so specifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * finalizers of all objects that have finalizers that have not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * automatically invoked are to be run before the Java runtime exits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * By default, finalization on exit is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <p>If there is a security manager,
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   293
     * its {@code checkExit} method is first called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * with 0 as its argument to ensure the exit is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * This could result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @param value true to enable finalization on exit, false to disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @deprecated  This method is inherently unsafe.  It may result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *      finalizers being called on live objects while other threads are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *      concurrently manipulating those objects, resulting in erratic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *      behavior or deadlock.
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   302
     *      This method is subject to removal in a future version of Java SE.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @throws  SecurityException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   305
     *        if a security manager exists and its {@code checkExit}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *        method doesn't allow the exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @see     java.lang.Runtime#exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see     java.lang.Runtime#gc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @see     java.lang.SecurityManager#checkExit(int)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
   311
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   313
    @Deprecated(since="1.2", forRemoval=true)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public static void runFinalizersOnExit(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                security.checkExit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                throw new SecurityException("runFinalizersOnExit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        Shutdown.setRunFinalizersOnExit(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Executes the specified string command in a separate process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   330
     * {@code exec(command)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   332
     * {@link #exec(String, String[], File) exec}{@code (command, null, null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param   command   a specified system command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   347
     *          If {@code command} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @throws  IllegalArgumentException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   350
     *          If {@code command} is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see     #exec(String[], String[], File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public Process exec(String command) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return exec(command, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Executes the specified string command in a separate process with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * specified environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   364
     * {@code exec(command, envp)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   366
     * {@link #exec(String, String[], File) exec}{@code (command, envp, null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param   command   a specified system command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *                    <i>name</i>=<i>value</i>, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   373
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   387
     *          If {@code command} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   388
     *          or one of the elements of {@code envp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @throws  IllegalArgumentException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   391
     *          If {@code command} is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see     #exec(String[], String[], File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public Process exec(String command, String[] envp) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return exec(command, envp, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Executes the specified string command in a separate process with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * specified environment and working directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   405
     * {@code exec(command, envp, dir)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   407
     * {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, dir)},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   408
     * where {@code cmdarray} is an array of all the tokens in
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   409
     * {@code command}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   411
     * <p>More precisely, the {@code command} string is broken
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * into tokens using a {@link StringTokenizer} created by the call
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   413
     * {@code new {@link StringTokenizer}(command)} with no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * further modification of the character categories.  The tokens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * produced by the tokenizer are then placed in the new string
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   416
     * array {@code cmdarray}, in the same order.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param   command   a specified system command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *                    <i>name</i>=<i>value</i>, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   423
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @param   dir       the working directory of the subprocess, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   427
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *                    the working directory of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   441
     *          If {@code command} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   442
     *          or one of the elements of {@code envp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @throws  IllegalArgumentException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   445
     *          If {@code command} is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public Process exec(String command, String[] envp, File dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (command.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            throw new IllegalArgumentException("Empty command");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        StringTokenizer st = new StringTokenizer(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        String[] cmdarray = new String[st.countTokens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        for (int i = 0; st.hasMoreTokens(); i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            cmdarray[i] = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return exec(cmdarray, envp, dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Executes the specified command and arguments in a separate process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   466
     * {@code exec(cmdarray)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   468
     * {@link #exec(String[], String[], File) exec}{@code (cmdarray, null, null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @param   cmdarray  array containing the command to call and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *                    its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   484
     *          If {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   485
     *          or one of the elements of {@code cmdarray} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @throws  IndexOutOfBoundsException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   488
     *          If {@code cmdarray} is an empty array
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   489
     *          (has length {@code 0})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public Process exec(String cmdarray[]) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return exec(cmdarray, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Executes the specified command and arguments in a separate process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * with the specified environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   502
     * {@code exec(cmdarray, envp)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   504
     * {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @param   cmdarray  array containing the command to call and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *                    its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *                    <i>name</i>=<i>value</i>, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   512
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   526
     *          If {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   527
     *          or one of the elements of {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   528
     *          or one of the elements of {@code envp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @throws  IndexOutOfBoundsException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   531
     *          If {@code cmdarray} is an empty array
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   532
     *          (has length {@code 0})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public Process exec(String[] cmdarray, String[] envp) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        return exec(cmdarray, envp, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * Executes the specified command and arguments in a separate process with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * the specified environment and working directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   545
     * <p>Given an array of strings {@code cmdarray}, representing the
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   546
     * tokens of a command line, and an array of strings {@code envp},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * representing "environment" variable settings, this method creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * a new process in which to execute the specified command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   550
     * <p>This method checks that {@code cmdarray} is a valid operating
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * system command.  Which commands are valid is system-dependent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * but at the very least the command must be a non-empty list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * non-null strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   555
     * <p>If {@code envp} is {@code null}, the subprocess inherits the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * environment settings of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *
9500
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   558
     * <p>A minimal set of system dependent environment variables may
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   559
     * be required to start a process on some operating systems.
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   560
     * As a result, the subprocess may inherit additional environment variable
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   561
     * settings beyond those in the specified environment.
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   562
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <p>{@link ProcessBuilder#start()} is now the preferred way to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * start a process with a modified environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   566
     * <p>The working directory of the new subprocess is specified by {@code dir}.
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   567
     * If {@code dir} is {@code null}, the subprocess inherits the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * current working directory of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <p>If a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * method is invoked with the first component of the array
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   573
     * {@code cmdarray} as its argument. This may result in a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * {@link SecurityException} being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * <p>Starting an operating system process is highly system-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Among the many things that can go wrong are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <li>The operating system program file was not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * <li>Access to the program file was denied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * <li>The working directory does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <p>In such cases an exception will be thrown.  The exact nature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * of the exception is system-dependent, but it will always be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * subclass of {@link IOException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
28872
82a09f5a7ed6 8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents: 28750
diff changeset
   588
     * <p>If the operating system does not support the creation of
82a09f5a7ed6 8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents: 28750
diff changeset
   589
     * processes, an {@link UnsupportedOperationException} will be thrown.
82a09f5a7ed6 8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents: 28750
diff changeset
   590
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @param   cmdarray  array containing the command to call and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *                    its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *                    <i>name</i>=<i>value</i>, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   598
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @param   dir       the working directory of the subprocess, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   602
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *                    the working directory of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *
28750
a1dae439cdab 8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents: 27184
diff changeset
   612
     * @throws  UnsupportedOperationException
a1dae439cdab 8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents: 27184
diff changeset
   613
     *          If the operating system does not support the creation of processes.
a1dae439cdab 8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents: 27184
diff changeset
   614
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   619
     *          If {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   620
     *          or one of the elements of {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   621
     *          or one of the elements of {@code envp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @throws  IndexOutOfBoundsException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   624
     *          If {@code cmdarray} is an empty array
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   625
     *          (has length {@code 0})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public Process exec(String[] cmdarray, String[] envp, File dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return new ProcessBuilder(cmdarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            .environment(envp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            .directory(dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            .start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * Returns the number of processors available to the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * <p> This value may change during a particular invocation of the virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * machine.  Applications that are sensitive to the number of available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * processors should therefore occasionally poll this property and adjust
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * their resource usage appropriately. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @return  the maximum number of processors available to the virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *          machine; never smaller than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public native int availableProcessors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * Returns the amount of free memory in the Java Virtual Machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Calling the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   655
     * {@code gc} method may result in increasing the value returned
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   656
     * by {@code freeMemory.}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @return  an approximation to the total amount of memory currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *          available for future allocated objects, measured in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public native long freeMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * Returns the total amount of memory in the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * The value returned by this method may vary over time, depending on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * the host environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Note that the amount of memory required to hold an object of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * given type may be implementation-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @return  the total amount of memory currently available for current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *          and future objects, measured in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public native long totalMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   677
     * Returns the maximum amount of memory that the Java virtual machine
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   678
     * will attempt to use.  If there is no inherent limit then the value
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   679
     * {@link java.lang.Long#MAX_VALUE} will be returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @return  the maximum amount of memory that the virtual machine will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *          attempt to use, measured in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    public native long maxMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * Runs the garbage collector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * Calling this method suggests that the Java virtual machine expend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * effort toward recycling unused objects in order to make the memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * they currently occupy available for quick reuse. When control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * returns from the method call, the virtual machine has made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * its best effort to recycle all discarded objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * <p>
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   695
     * The name {@code gc} stands for "garbage
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * collector". The virtual machine performs this recycling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * process automatically as needed, in a separate thread, even if the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   698
     * {@code gc} method is not invoked explicitly.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * The method {@link System#gc()} is the conventional and convenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    public native void gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /* Wormhole for calling java.lang.ref.Finalizer.runFinalization */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    private static native void runFinalization0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Runs the finalization methods of any objects pending finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * Calling this method suggests that the Java virtual machine expend
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   711
     * effort toward running the {@code finalize} methods of objects
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   712
     * that have been found to be discarded but whose {@code finalize}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * methods have not yet been run. When control returns from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * method call, the virtual machine has made a best effort to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * complete all outstanding finalizations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * The virtual machine performs the finalization process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * automatically as needed, in a separate thread, if the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   719
     * {@code runFinalization} method is not invoked explicitly.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * The method {@link System#runFinalization()} is the conventional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * and convenient means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @see     java.lang.Object#finalize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    public void runFinalization() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        runFinalization0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /**
37606
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   731
     * Not implemented, does nothing.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *
37606
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   733
     * @deprecated
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   734
     * This method was intended to control instruction tracing.
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   735
     * It has been superseded by JVM-specific tracing mechanisms.
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   736
     *
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   737
     * @param on ignored
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     */
37606
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   739
    @Deprecated(since="9", forRemoval=true)
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   740
    public void traceInstructions(boolean on) { }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /**
37606
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   743
     * Not implemented, does nothing.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *
37606
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   745
     * @deprecated
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   746
     * This method was intended to control method call tracing.
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   747
     * It has been superseded by JVM-specific tracing mechanisms.
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   748
     *
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   749
     * @param on ignored
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
37606
e74fdd1e637f 8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents: 37521
diff changeset
   751
    @Deprecated(since="9", forRemoval=true)
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   752
    public void traceMethodCalls(boolean on) { }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /**
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   755
     * Loads the native library specified by the filename argument.  The filename
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   756
     * argument must be an absolute path name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * (for example
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   758
     * {@code Runtime.getRuntime().load("/home/avh/lib/libX11.so");}).
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   759
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   760
     * If the filename argument, when stripped of any platform-specific library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   761
     * prefix, path, and file extension, indicates a library whose name is,
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   762
     * for example, L, and a native library called L is statically linked
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   763
     * with the VM, then the JNI_OnLoad_L function exported by the library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   764
     * is invoked rather than attempting to load a dynamic library.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   765
     * A filename matching the argument does not have to exist in the file
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   766
     * system. See the JNI Specification for more details.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   767
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   768
     * Otherwise, the filename argument is mapped to a native library image in
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   769
     * an implementation-dependent manner.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * <p>
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   771
     * First, if there is a security manager, its {@code checkLink}
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   772
     * method is called with the {@code filename} as its argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * This is similar to the method {@link #loadLibrary(String)}, but it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * accepts a general file name as an argument rather than just a library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * name, allowing any file of native code to be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * The method {@link System#load(String)} is the conventional and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * convenient means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @param      filename   the file to load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @exception  SecurityException  if a security manager exists and its
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   784
     *             {@code checkLink} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *             loading of the specified dynamic library
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   786
     * @exception  UnsatisfiedLinkError  if either the filename is not an
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   787
     *             absolute path name, the native library is not statically
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   788
     *             linked with the VM, or the library cannot be mapped to
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   789
     *             a native library image by the host system.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   790
     * @exception  NullPointerException if {@code filename} is
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   791
     *             {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @see        java.lang.Runtime#getRuntime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
   796
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    public void load(String filename) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
   798
        load0(Reflection.getCallerClass(), filename);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 9500
diff changeset
   801
    synchronized void load0(Class<?> fromClass, String filename) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            security.checkLink(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        if (!(new File(filename).isAbsolute())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            throw new UnsatisfiedLinkError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                "Expecting an absolute path of the library: " + filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        ClassLoader.loadLibrary(fromClass, filename, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    /**
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   814
     * Loads the native library specified by the {@code libname}
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   815
     * argument.  The {@code libname} argument must not contain any platform
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   816
     * specific prefix, file extension or path. If a native library
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   817
     * called {@code libname} is statically linked with the VM, then the
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   818
     * JNI_OnLoad_{@code libname} function exported by the library is invoked.
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   819
     * See the JNI Specification for more details.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   820
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   821
     * Otherwise, the libname argument is loaded from a system library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   822
     * location and mapped to a native library image in an implementation-
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   823
     * dependent manner.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * <p>
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   825
     * First, if there is a security manager, its {@code checkLink}
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   826
     * method is called with the {@code libname} as its argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * The method {@link System#loadLibrary(String)} is the conventional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * and convenient means of invoking this method. If native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * methods are to be used in the implementation of a class, a standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * strategy is to put the native code in a library file (call it
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   833
     * {@code LibFile}) and then to put a static initializer:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * static { System.loadLibrary("LibFile"); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * within the class declaration. When the class is loaded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * initialized, the necessary native code implementation for the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * methods will then be loaded as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * If this method is called more than once with the same library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * name, the second and subsequent calls are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @param      libname   the name of the library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @exception  SecurityException  if a security manager exists and its
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   846
     *             {@code checkLink} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *             loading of the specified dynamic library
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   848
     * @exception  UnsatisfiedLinkError if either the libname argument
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   849
     *             contains a file path, the native library is not statically
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   850
     *             linked with the VM,  or the library cannot be mapped to a
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   851
     *             native library image by the host system.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   852
     * @exception  NullPointerException if {@code libname} is
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   853
     *             {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
   857
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    public void loadLibrary(String libname) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
   859
        loadLibrary0(Reflection.getCallerClass(), libname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 9500
diff changeset
   862
    synchronized void loadLibrary0(Class<?> fromClass, String libname) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            security.checkLink(libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (libname.indexOf((int)File.separatorChar) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            throw new UnsatisfiedLinkError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    "Directory separator should not appear in library name: " + libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        ClassLoader.loadLibrary(fromClass, libname, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * Creates a localized version of an input stream. This method takes
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   876
     * an {@code InputStream} and returns an {@code InputStream}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * equivalent to the argument in all respects except that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * localized: as characters in the local character set are read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * the stream, they are automatically converted from the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * character set to Unicode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * If the argument is already a localized stream, it may be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * as the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @param      in InputStream to localize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @return     a localized input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @see        java.io.InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @see        java.io.BufferedReader#BufferedReader(java.io.Reader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @see        java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @deprecated As of JDK&nbsp;1.1, the preferred way to translate a byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * stream in the local encoding into a character stream in Unicode is via
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   892
     * the {@code InputStreamReader} and {@code BufferedReader}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * classes.
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   894
     * This method is subject to removal in a future version of Java SE.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     */
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   896
    @Deprecated(since="1.1", forRemoval=true)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    public InputStream getLocalizedInputStream(InputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * Creates a localized version of an output stream. This method
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   903
     * takes an {@code OutputStream} and returns an
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   904
     * {@code OutputStream} equivalent to the argument in all respects
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * except that it is localized: as Unicode characters are written to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * the stream, they are automatically converted to the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * character set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * If the argument is already a localized stream, it may be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * as the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @deprecated As of JDK&nbsp;1.1, the preferred way to translate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * Unicode character stream into a byte stream in the local encoding is via
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   914
     * the {@code OutputStreamWriter}, {@code BufferedWriter}, and
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   915
     * {@code PrintWriter} classes.
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   916
     * This method is subject to removal in a future version of Java SE.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @param      out OutputStream to localize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @return     a localized output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @see        java.io.OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @see        java.io.BufferedWriter#BufferedWriter(java.io.Writer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @see        java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @see        java.io.PrintWriter#PrintWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     */
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   925
    @Deprecated(since="1.1", forRemoval=true)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    public OutputStream getLocalizedOutputStream(OutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   930
    /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   931
     * Returns the version of the Java Runtime Environment as a {@link
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   932
     * Runtime.Version}.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   933
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   934
     * @return  the {@link Runtime.Version} of the Java Runtime Environment
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   935
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   936
     * @since  9
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   937
     */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   938
    public static Version version() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   939
        if (version == null) {
39302
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
   940
            version = new Version(VersionProps.versionNumbers(),
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
   941
                    VersionProps.pre(), VersionProps.build(),
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
   942
                    VersionProps.optional());
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   943
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   944
        return version;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   945
    }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   946
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   947
    /**
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
   948
     * A representation of a version string for an implementation of the
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   949
     * Java&nbsp;SE Platform.  A version string contains a version number
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   950
     * optionally followed by pre-release and build information.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   951
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   952
     * <h2><a name="verNum">Version numbers</a></h2>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   953
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   954
     * <p> A <em>version number</em>, {@code $VNUM}, is a non-empty sequence
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   955
     * of elements separated by period characters (U+002E).  An element is
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   956
     * either zero, or a unsigned integer numeral without leading zeros.  The
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   957
     * final element in a version number must not be zero.  The format is:
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   958
     * </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   959
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   960
     * <blockquote><pre>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   961
     *     ^[1-9][0-9]*(((\.0)*\.[1-9][0-9]*)*)*$
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   962
     * </pre></blockquote>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   963
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   964
     * <p> The sequence may be of arbitrary length but the first three
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   965
     * elements are assigned specific meanings, as follows:</p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   966
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   967
     * <blockquote><pre>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   968
     *     $MAJOR.$MINOR.$SECURITY
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   969
     * </pre></blockquote>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   970
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   971
     * <ul>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   972
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   973
     * <li><p> <a name="major">{@code $MAJOR}</a> --- The major version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   974
     * number, incremented for a major release that contains significant new
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   975
     * features as specified in a new edition of the Java&#160;SE Platform
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   976
     * Specification, <em>e.g.</em>, <a
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   977
     * href="https://jcp.org/en/jsr/detail?id=337">JSR 337</a> for
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   978
     * Java&#160;SE&#160;8.  Features may be removed in a major release, given
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   979
     * advance notice at least one major release ahead of time, and
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   980
     * incompatible changes may be made when justified. The {@code $MAJOR}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   981
     * version number of JDK&#160;8 is {@code 8}; the {@code $MAJOR} version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   982
     * number of JDK&#160;9 is {@code 9}.  When {@code $MAJOR} is incremented,
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   983
     * all subsequent elements are removed. </p></li>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   984
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   985
     * <li><p> <a name="minor">{@code $MINOR}</a> --- The minor version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   986
     * number, incremented for a minor update release that may contain
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   987
     * compatible bug fixes, revisions to standard APIs mandated by a
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   988
     * <a href="https://jcp.org/en/procedures/jcp2#5.3">Maintenance Release</a>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   989
     * of the relevant Platform Specification, and implementation features
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   990
     * outside the scope of that Specification such as new JDK-specific APIs,
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   991
     * additional service providers, new garbage collectors, and ports to new
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   992
     * hardware architectures. </p></li>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   993
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   994
     * <li><p> <a name="security">{@code $SECURITY}</a> --- The security
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   995
     * level, incremented for a security update release that contains critical
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   996
     * fixes including those necessary to improve security.  {@code $SECURITY}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   997
     * is <strong>not</strong> reset when {@code $MINOR} is incremented.  A
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   998
     * higher value of {@code $SECURITY} for a given {@code $MAJOR} value,
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
   999
     * therefore, always indicates a more secure release, regardless of the
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1000
     * value of {@code $MINOR}. </p></li>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1001
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1002
     * </ul>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1003
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1004
     * <p> The fourth and later elements of a version number are free for use
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1005
     * by downstream consumers of this code base.  Such a consumer may,
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1006
     * <em>e.g.</em>, use the fourth element to identify patch releases which
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1007
     * contain a small number of critical non-security fixes in addition to
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1008
     * the security fixes in the corresponding security release. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1009
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1010
     * <p> The version number does not include trailing zero elements;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1011
     * <em>i.e.</em>, {@code $SECURITY} is omitted if it has the value zero,
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1012
     * and {@code $MINOR} is omitted if both {@code $MINOR} and {@code
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1013
     * $SECURITY} have the value zero. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1014
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1015
     * <p> The sequence of numerals in a version number is compared to another
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1016
     * such sequence in numerical, pointwise fashion; <em>e.g.</em>, {@code
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1017
     * 9.9.1} is less than {@code 9.10.3}. If one sequence is shorter than
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1018
     * another then the missing elements of the shorter sequence are
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1019
     * considered to be less than the corresponding elements of the longer
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1020
     * sequence; <em>e.g.</em>, {@code 9.1.2} is less than {@code 9.1.2.1}.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1021
     * </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1022
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1023
     * <h2><a name="verStr">Version strings</a></h2>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1024
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1025
     * <p> A <em>version string</em>, {@code $VSTR}, consists of a version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1026
     * number {@code $VNUM}, as described above, optionally followed by
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1027
     * pre-release and build information, in the format </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1028
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1029
     * <blockquote><pre>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1030
     *     $VNUM(-$PRE)?(\+($BUILD)?(-$OPT)?)?
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1031
     * </pre></blockquote>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1032
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1033
     * <p> where: </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1034
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1035
     * <ul>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1036
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1037
     * <li><p> <a name="pre">{@code $PRE}</a>, matching {@code ([a-zA-Z0-9]+)}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1038
     * --- A pre-release identifier.  Typically {@code ea}, for a
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1039
     * potentially unstable early-access release under active development,
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1040
     * or {@code internal}, for an internal developer build.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1041
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1042
     * <li><p> <a name="build">{@code $BUILD}</a>, matching {@code
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1043
     * (0|[1-9][0-9]*)} --- The build number, incremented for each promoted
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1044
     * build.  {@code $BUILD} is reset to {@code 1} when any portion of {@code
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1045
     * $VNUM} is incremented. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1046
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1047
     * <li><p> <a name="opt">{@code $OPT}</a>, matching {@code
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1048
     * ([-a-zA-Z0-9\.]+)} --- Additional build information, if desired.  In
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1049
     * the case of an {@code internal} build this will often contain the date
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1050
     * and time of the build. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1051
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1052
     * </ul>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1053
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1054
     * <p> A version number {@code 10-ea} matches {@code $VNUM = "10"} and
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1055
     * {@code $PRE = "ea"}.  The version number {@code 10+-ea} matches
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1056
     * {@code $VNUM = "10"} and {@code $OPT = "ea"}. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1057
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1058
     * <p> When comparing two version strings, the value of {@code $OPT}, if
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1059
     * present, may or may not be significant depending on the chosen
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1060
     * comparison method.  The comparison methods {@link #compareTo(Version)
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
  1061
     * compareTo()} and {@link #compareToIgnoreOptional(Version)
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
  1062
     * compareToIgnoreOptional()} should be used consistently with the
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1063
     * corresponding methods {@link #equals(Object) equals()} and {@link
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
  1064
     * #equalsIgnoreOptional(Object) equalsIgnoreOptional()}.  </p>
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1065
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1066
     * <p> A <em>short version string</em>, {@code $SVSTR}, often useful in
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1067
     * less formal contexts, is a version number optionally followed by a
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1068
     * pre-release identifier:
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1069
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1070
     * <blockquote><pre>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1071
     *     $VNUM(-$PRE)?
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1072
     * </pre></blockquote>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1073
     *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1074
     * @since  9
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1075
     */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1076
    public static class Version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1077
        implements Comparable<Version>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1078
    {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1079
        private final List<Integer>     version;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1080
        private final Optional<String>  pre;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1081
        private final Optional<Integer> build;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1082
        private final Optional<String>  optional;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1083
39302
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1084
        Version(List<Integer> version, Optional<String> pre,
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1085
                Optional<Integer> build, Optional<String> optional) {
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1086
            this.version = Collections.unmodifiableList(version);
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1087
            this.pre = pre;
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1088
            this.build = build;
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1089
            this.optional = optional;
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1090
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1091
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1092
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1093
         * Parses the given string as a valid
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1094
         * <a href="#verStr">version string</a> containing a
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1095
         * <a href="#verNum">version number</a> followed by pre-release and
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1096
         * build information.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1097
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1098
         * @param  s
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1099
         *         A string to interpret as a version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1100
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1101
         * @throws  IllegalArgumentException
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1102
         *          If the given string cannot be interpreted as a valid
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1103
         *          version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1104
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1105
         * @throws  NullPointerException
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1106
         *          If the given string is {@code null}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1107
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1108
         * @throws  NumberFormatException
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1109
         *          If an element of the version number or the build number
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1110
         *          cannot be represented as an {@link Integer}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1111
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1112
         * @return  The Version of the given string
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1113
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1114
        public static Version parse(String s) {
39889
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1115
            if (s == null)
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1116
                throw new NullPointerException();
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1117
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1118
            // Shortcut to avoid initializing VersionPattern when creating
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1119
            // major version constants during startup
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1120
            if (isSimpleNumber(s)) {
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1121
                return new Version(List.of(Integer.parseInt(s)),
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1122
                        Optional.empty(), Optional.empty(), Optional.empty());
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1123
            }
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1124
            Matcher m = VersionPattern.VSTR_PATTERN.matcher(s);
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1125
            if (!m.matches())
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1126
                throw new IllegalArgumentException("Invalid version string: '"
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1127
                                                   + s + "'");
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1128
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1129
            // $VNUM is a dot-separated list of integers of arbitrary length
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1130
            List<Integer> version = new ArrayList<>();
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1131
            for (String i : m.group(VersionPattern.VNUM_GROUP).split("\\."))
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1132
                version.add(Integer.parseInt(i));
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1133
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1134
            Optional<String> pre = Optional.ofNullable(
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1135
                    m.group(VersionPattern.PRE_GROUP));
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1136
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1137
            String b = m.group(VersionPattern.BUILD_GROUP);
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1138
            // $BUILD is an integer
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1139
            Optional<Integer> build = (b == null)
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1140
                ? Optional.empty()
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1141
                : Optional.of(Integer.parseInt(b));
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1142
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1143
            Optional<String> optional = Optional.ofNullable(
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1144
                    m.group(VersionPattern.OPT_GROUP));
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1145
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1146
            // empty '+'
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1147
            if ((m.group(VersionPattern.PLUS_GROUP) != null)
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1148
                    && !build.isPresent()) {
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1149
                if (optional.isPresent()) {
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1150
                    if (pre.isPresent())
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1151
                        throw new IllegalArgumentException("'+' found with"
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1152
                            + " pre-release and optional components:'" + s
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1153
                            + "'");
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1154
                } else {
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1155
                    throw new IllegalArgumentException("'+' found with neither"
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1156
                        + " build or optional components: '" + s + "'");
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1157
                }
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1158
            }
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1159
            return new Version(version, pre, build, optional);
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1160
        }
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1161
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1162
        private static boolean isSimpleNumber(String s) {
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1163
            for (int i = 0; i < s.length(); i++) {
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1164
                char c = s.charAt(i);
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1165
                char lowerBound = (i > 0) ? '0' : '1';
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1166
                if (c < lowerBound || c > '9') {
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1167
                    return false;
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1168
                }
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1169
            }
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1170
            return true;
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1171
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1172
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1173
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1174
         * Returns the <a href="#major">major</a> version number.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1175
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1176
         * @return  The major version number
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1177
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1178
        public int major() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1179
            return version.get(0);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1180
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1181
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1182
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1183
         * Returns the <a href="#minor">minor</a> version number or zero if it
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1184
         * was not set.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1185
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1186
         * @return  The minor version number or zero if it was not set
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1187
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1188
        public int minor() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1189
            return (version.size() > 1 ? version.get(1) : 0);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1190
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1191
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1192
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1193
         * Returns the <a href="#security">security</a> version number or zero
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1194
         * if it was not set.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1195
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1196
         * @return  The security version number or zero if it was not set
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1197
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1198
        public int security() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1199
            return (version.size() > 2 ? version.get(2) : 0);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1200
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1201
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1202
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1203
         * Returns an unmodifiable {@link java.util.List List} of the
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1204
         * integer numerals contained in the <a href="#verNum">version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1205
         * number</a>.  The {@code List} always contains at least one
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1206
         * element corresponding to the <a href="#major">major version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1207
         * number</a>.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1208
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1209
         * @return  An unmodifiable list of the integer numerals
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1210
         *          contained in the version number
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1211
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1212
        public List<Integer> version() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1213
            return version;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1214
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1215
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1216
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1217
         * Returns the optional <a href="#pre">pre-release</a> information.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1218
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1219
         * @return  The optional pre-release information as a String
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1220
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1221
        public Optional<String> pre() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1222
            return pre;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1223
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1224
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1225
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1226
         * Returns the <a href="#build">build number</a>.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1227
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1228
         * @return  The optional build number.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1229
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1230
        public Optional<Integer> build() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1231
            return build;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1232
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1233
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1234
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1235
         * Returns <a href="#opt">optional</a> additional identifying build
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1236
         * information.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1237
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1238
         * @return  Additional build information as a String
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1239
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1240
        public Optional<String> optional() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1241
            return optional;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1242
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1243
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1244
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1245
         * Compares this version to another.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1246
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1247
         * <p> Each of the components in the <a href="#verStr">version</a> is
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1248
         * compared in the follow order of precedence: version numbers,
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1249
         * pre-release identifiers, build numbers, optional build information.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1250
         * </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1251
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1252
         * <p> Comparison begins by examining the sequence of version numbers.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1253
         * If one sequence is shorter than another, then the missing elements
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1254
         * of the shorter sequence are considered to be less than the
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1255
         * corresponding elements of the longer sequence. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1256
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1257
         * <p> A version with a pre-release identifier is always considered to
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1258
         * be less than a version without one.  Pre-release identifiers are
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1259
         * compared numerically when they consist only of digits, and
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1260
         * lexicographically otherwise.  Numeric identifiers are considered to
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1261
         * be less than non-numeric identifiers.  </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1262
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1263
         * <p> A version without a build number is always less than one with a
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1264
         * build number; otherwise build numbers are compared numerically. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1265
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1266
         * <p> The optional build information is compared lexicographically.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1267
         * During this comparison, a version with optional build information is
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1268
         * considered to be greater than a version without one. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1269
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1270
         * <p> A version is not comparable to any other type of object.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1271
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1272
         * @param  ob
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1273
         *         The object to be compared
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1274
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1275
         * @return  A negative integer, zero, or a positive integer if this
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1276
         *          {@code Version} is less than, equal to, or greater than the
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1277
         *          given {@code Version}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1278
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1279
         * @throws  NullPointerException
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1280
         *          If the given object is {@code null}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1281
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1282
        @Override
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1283
        public int compareTo(Version ob) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1284
            return compare(ob, false);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1285
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1286
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1287
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1288
         * Compares this version to another disregarding optional build
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1289
         * information.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1290
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1291
         * <p> Two versions are compared by examining the version string as
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1292
         * described in {@link #compareTo(Version)} with the exception that the
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1293
         * optional build information is always ignored. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1294
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1295
         * <p> A version is not comparable to any other type of object.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1296
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1297
         * @param  ob
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1298
         *         The object to be compared
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1299
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1300
         * @return  A negative integer, zero, or a positive integer if this
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1301
         *          {@code Version} is less than, equal to, or greater than the
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1302
         *          given {@code Version}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1303
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1304
         * @throws  NullPointerException
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1305
         *          If the given object is {@code null}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1306
         */
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
  1307
        public int compareToIgnoreOptional(Version ob) {
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1308
            return compare(ob, true);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1309
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1310
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1311
        private int compare(Version ob, boolean ignoreOpt) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1312
            if (ob == null)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1313
                throw new NullPointerException("Invalid argument");
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1314
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1315
            int ret = compareVersion(ob);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1316
            if (ret != 0)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1317
                return ret;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1318
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1319
            ret = comparePre(ob);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1320
            if (ret != 0)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1321
                return ret;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1322
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1323
            ret = compareBuild(ob);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1324
            if (ret != 0)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1325
                return ret;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1326
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1327
            if (!ignoreOpt)
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
  1328
                return compareOptional(ob);
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1329
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1330
            return 0;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1331
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1332
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1333
        private int compareVersion(Version ob) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1334
            int size = version.size();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1335
            int oSize = ob.version().size();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1336
            int min = Math.min(size, oSize);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1337
            for (int i = 0; i < min; i++) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1338
                Integer val = version.get(i);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1339
                Integer oVal = ob.version().get(i);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1340
                if (val != oVal)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1341
                    return val - oVal;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1342
            }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1343
            if (size != oSize)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1344
                return size - oSize;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1345
            return 0;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1346
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1347
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1348
        private int comparePre(Version ob) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1349
            Optional<String> oPre = ob.pre();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1350
            if (!pre.isPresent()) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1351
                if (oPre.isPresent())
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1352
                    return 1;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1353
            } else {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1354
                if (!oPre.isPresent())
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1355
                    return -1;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1356
                String val = pre.get();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1357
                String oVal = oPre.get();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1358
                if (val.matches("\\d+")) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1359
                    return (oVal.matches("\\d+")
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1360
                        ? (new BigInteger(val)).compareTo(new BigInteger(oVal))
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1361
                        : -1);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1362
                } else {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1363
                    return (oVal.matches("\\d+")
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1364
                        ? 1
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1365
                        : val.compareTo(oVal));
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1366
                }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1367
            }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1368
            return 0;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1369
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1370
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1371
        private int compareBuild(Version ob) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1372
            Optional<Integer> oBuild = ob.build();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1373
            if (oBuild.isPresent()) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1374
                return (build.isPresent()
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1375
                        ? build.get().compareTo(oBuild.get())
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1376
                        : 1);
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1377
            } else if (build.isPresent()) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1378
                return -1;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1379
            }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1380
            return 0;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1381
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1382
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
  1383
        private int compareOptional(Version ob) {
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1384
            Optional<String> oOpt = ob.optional();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1385
            if (!optional.isPresent()) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1386
                if (oOpt.isPresent())
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1387
                    return -1;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1388
            } else {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1389
                if (!oOpt.isPresent())
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1390
                    return 1;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1391
                return optional.get().compareTo(oOpt.get());
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1392
            }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1393
            return 0;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1394
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1395
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1396
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1397
         * Returns a string representation of this version.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1398
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1399
         * @return  The version string
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1400
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1401
        @Override
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1402
        public String toString() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1403
            StringBuilder sb
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1404
                = new StringBuilder(version.stream()
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1405
                    .map(Object::toString)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1406
                    .collect(Collectors.joining(".")));
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1407
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1408
            pre.ifPresent(v -> sb.append("-").append(v));
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1409
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1410
            if (build.isPresent()) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1411
                sb.append("+").append(build.get());
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1412
                if (optional.isPresent())
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1413
                    sb.append("-").append(optional.get());
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1414
            } else {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1415
                if (optional.isPresent()) {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1416
                    sb.append(pre.isPresent() ? "-" : "+-");
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1417
                    sb.append(optional.get());
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1418
                }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1419
            }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1420
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1421
            return sb.toString();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1422
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1423
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1424
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1425
         * Determines whether this {@code Version} is equal to another object.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1426
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1427
         * <p> Two {@code Version}s are equal if and only if they represent the
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1428
         * same version string.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1429
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1430
         * <p> This method satisfies the general contract of the {@link
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1431
         * Object#equals(Object) Object.equals} method. </p>
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1432
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1433
         * @param  ob
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1434
         *         The object to which this {@code Version} is to be compared
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1435
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1436
         * @return  {@code true} if, and only if, the given object is a {@code
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1437
         *          Version} that is identical to this {@code Version}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1438
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1439
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1440
        @Override
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1441
        public boolean equals(Object ob) {
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
  1442
            boolean ret = equalsIgnoreOptional(ob);
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1443
            if (!ret)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1444
                return false;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1445
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1446
            Version that = (Version)ob;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1447
            return (this.optional().equals(that.optional()));
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1448
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1449
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1450
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1451
         * Determines whether this {@code Version} is equal to another
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1452
         * disregarding optional build information.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1453
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1454
         * <p> Two {@code Version}s are equal if and only if they represent the
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1455
         * same version string disregarding the optional build information.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1456
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1457
         * @param  ob
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1458
         *         The object to which this {@code Version} is to be compared
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1459
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1460
         * @return  {@code true} if, and only if, the given object is a {@code
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1461
         *          Version} that is identical to this {@code Version}
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1462
         *          ignoring the optinal build information
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1463
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1464
         */
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 39302
diff changeset
  1465
        public boolean equalsIgnoreOptional(Object ob) {
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1466
            if (this == ob)
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1467
                return true;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1468
            if (!(ob instanceof Version))
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1469
                return false;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1470
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1471
            Version that = (Version)ob;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1472
            return (this.version().equals(that.version())
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1473
                && this.pre().equals(that.pre())
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1474
                && this.build().equals(that.build()));
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1475
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1476
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1477
        /**
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1478
         * Returns the hash code of this version.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1479
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1480
         * <p> This method satisfies the general contract of the {@link
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1481
         * Object#hashCode Object.hashCode} method.
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1482
         *
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1483
         * @return  The hashcode of this version
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1484
         */
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1485
        @Override
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1486
        public int hashCode() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1487
            int h = 1;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1488
            int p = 17;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1489
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1490
            h = p * h + version.hashCode();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1491
            h = p * h + pre.hashCode();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1492
            h = p * h + build.hashCode();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1493
            h = p * h + optional.hashCode();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1494
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1495
            return h;
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1496
        }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1497
    }
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37606
diff changeset
  1498
39889
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1499
    private static class VersionPattern {
39302
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1500
        // $VNUM(-$PRE)?(\+($BUILD)?(\-$OPT)?)?
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1501
        // RE limits the format of version strings
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1502
        // ([1-9][0-9]*(?:(?:\.0)*\.[1-9][0-9]*)*)(?:-([a-zA-Z0-9]+))?(?:(\+)(0|[1-9][0-9]*)?)?(?:-([-a-zA-Z0-9.]+))?
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1503
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1504
        private static final String VNUM
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1505
            = "(?<VNUM>[1-9][0-9]*(?:(?:\\.0)*\\.[1-9][0-9]*)*)";
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1506
        private static final String PRE      = "(?:-(?<PRE>[a-zA-Z0-9]+))?";
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1507
        private static final String BUILD
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1508
            = "(?:(?<PLUS>\\+)(?<BUILD>0|[1-9][0-9]*)?)?";
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1509
        private static final String OPT      = "(?:-(?<OPT>[-a-zA-Z0-9.]+))?";
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1510
        private static final String VSTR_FORMAT
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1511
            = "^" + VNUM + PRE + BUILD + OPT + "$";
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1512
39889
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1513
        static final Pattern VSTR_PATTERN = Pattern.compile(VSTR_FORMAT);
39302
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1514
39889
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1515
        static final String VNUM_GROUP  = "VNUM";
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1516
        static final String PRE_GROUP   = "PRE";
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1517
        static final String PLUS_GROUP  = "PLUS";
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1518
        static final String BUILD_GROUP = "BUILD";
2e82e1c36e90 8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents: 39766
diff changeset
  1519
        static final String OPT_GROUP   = "OPT";
39302
aa8d0bc2a6d2 8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents: 38432
diff changeset
  1520
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
}