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