jdk/src/java.base/share/classes/java/util/jar/JarFile.java
author sdrach
Tue, 23 Aug 2016 11:26:41 -0700
changeset 40539 12bb7768ae6e
parent 39758 28c2c63fc09f
child 40812 dc3755b63ade
permissions -rw-r--r--
8164585: JarFile::isMultiRelease does not return true in all cases where it should return true Reviewed-by: alanb, psandoz Contributed-by: steve.drach@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37785
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4152
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: 4152
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: 4152
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4152
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4152
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.util.jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.ref.SoftReference;
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
    30
import java.net.URL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
17421
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
    32
import java.util.stream.Stream;
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
    33
import java.util.stream.StreamSupport;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.zip.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.CodeSigner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.cert.Certificate;
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
    37
import java.security.CodeSource;
32834
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 32037
diff changeset
    38
import jdk.internal.misc.SharedSecrets;
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
    39
import sun.security.action.GetPropertyAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.util.ManifestEntryVerifier;
22578
ff8d54ac7c5c 8031572: jarsigner -verify exits with 0 when a jar file is not properly signed
weijun
parents: 22342
diff changeset
    41
import sun.security.util.SignatureFileVerifier;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
    44
 * The {@code JarFile} class is used to read the contents of a jar file
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
    45
 * from any file that can be opened with {@code java.io.RandomAccessFile}.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
    46
 * It extends the class {@code java.util.zip.ZipFile} with support
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    47
 * for reading an optional {@code Manifest} entry, and support for
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    48
 * processing multi-release jar files.  The {@code Manifest} can be used
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    49
 * to specify meta-information about the jar file and its entries.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    50
 *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    51
 * <p>A multi-release jar file is a jar file that contains
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    52
 * a manifest with a main attribute named "Multi-Release",
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    53
 * a set of "base" entries, some of which are public classes with public
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    54
 * or protected methods that comprise the public interface of the jar file,
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    55
 * and a set of "versioned" entries contained in subdirectories of the
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    56
 * "META-INF/versions" directory.  The versioned entries are partitioned by the
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    57
 * major version of the Java platform.  A versioned entry, with a version
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    58
 * {@code n}, {@code 8 < n}, in the "META-INF/versions/{n}" directory overrides
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    59
 * the base entry as well as any entry with a version number {@code i} where
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    60
 * {@code 8 < i < n}.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    61
 *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    62
 * <p>By default, a {@code JarFile} for a multi-release jar file is configured
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    63
 * to process the multi-release jar file as if it were a plain (unversioned) jar
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    64
 * file, and as such an entry name is associated with at most one base entry.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    65
 * The {@code JarFile} may be configured to process a multi-release jar file by
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    66
 * creating the {@code JarFile} with the
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
    67
 * {@link JarFile#JarFile(File, boolean, int, Runtime.Version)} constructor.  The
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
    68
 * {@code Runtime.Version} object sets a maximum version used when searching for
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    69
 * versioned entries.  When so configured, an entry name
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    70
 * can correspond with at most one base entry and zero or more versioned
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    71
 * entries. A search is required to associate the entry name with the latest
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    72
 * versioned entry whose version is less than or equal to the maximum version
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    73
 * (see {@link #getEntry(String)}).
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    74
 *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    75
 * <p>Class loaders that utilize {@code JarFile} to load classes from the
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    76
 * contents of {@code JarFile} entries should construct the {@code JarFile}
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
    77
 * by invoking the {@link JarFile#JarFile(File, boolean, int, Runtime.Version)}
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
    78
 * constructor with the value {@code Runtime.version()} assigned to the last
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    79
 * argument.  This assures that classes compatible with the major
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    80
 * version of the running JVM are loaded from multi-release jar files.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    81
 *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    82
 * <p>If the verify flag is on when opening a signed jar file, the content of
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    83
 * the file is verified against its signature embedded inside the file. Please
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    84
 * note that the verification process does not include validating the signer's
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    85
 * certificate. A caller should inspect the return value of
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    86
 * {@link JarEntry#getCodeSigners()} to further determine if the signature
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    87
 * can be trusted.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
    89
 * <p> Unless otherwise noted, passing a {@code null} argument to a constructor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * or method in this class will cause a {@link NullPointerException} to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    93
 * @implNote
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    94
 * <div class="block">
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    95
 * If the API can not be used to configure a {@code JarFile} (e.g. to override
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    96
 * the configuration of a compiled application or library), two {@code System}
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    97
 * properties are available.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    98
 * <ul>
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
    99
 * <li>
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   100
 * {@code jdk.util.jar.version} can be assigned a value that is the
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   101
 * {@code String} representation of a non-negative integer
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   102
 * {@code <= Runtime.version().major()}.  The value is used to set the effective
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   103
 * runtime version to something other than the default value obtained by
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   104
 * evaluating {@code Runtime.version().major()}. The effective runtime version
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   105
 * is the version that the {@link JarFile#JarFile(File, boolean, int, Runtime.Version)}
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   106
 * constructor uses when the value of the last argument is
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   107
 * {@code JarFile.runtimeVersion()}.
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   108
 * </li>
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   109
 * <li>
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   110
 * {@code jdk.util.jar.enableMultiRelease} can be assigned one of the three
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   111
 * {@code String} values <em>true</em>, <em>false</em>, or <em>force</em>.  The
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   112
 * value <em>true</em>, the default value, enables multi-release jar file
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   113
 * processing.  The value <em>false</em> disables multi-release jar processing,
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   114
 * ignoring the "Multi-Release" manifest attribute, and the versioned
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   115
 * directories in a multi-release jar file if they exist.  Furthermore,
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   116
 * the method {@link JarFile#isMultiRelease()} returns <em>false</em>. The value
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   117
 * <em>force</em> causes the {@code JarFile} to be initialized to runtime
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   118
 * versioning after construction.  It effectively does the same as this code:
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   119
 * {@code (new JarFile(File, boolean, int, JarFile.runtimeVersion())}.
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   120
 * </li>
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   121
 * </ul>
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   122
 * </div>
22316
5668a8abf212 8024659: Clarify JarFile API
weijun
parents: 19409
diff changeset
   123
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @author  David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @see     Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * @see     java.util.zip.ZipFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * @see     java.util.jar.JarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
class JarFile extends ZipFile {
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   132
    private final static Runtime.Version BASE_VERSION;
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   133
    private final static int BASE_VERSION_MAJOR;
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   134
    private final static Runtime.Version RUNTIME_VERSION;
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   135
    private final static boolean MULTI_RELEASE_ENABLED;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   136
    private final static boolean MULTI_RELEASE_FORCED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private SoftReference<Manifest> manRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private JarEntry manEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private JarVerifier jv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private boolean jvInitialized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private boolean verify;
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   142
    private final Runtime.Version version;  // current version
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   143
    private final int versionMajor;         // version.major()
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   144
    private boolean isMultiRelease;         // is jar multi-release?
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   145
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   146
    // indicates if Class-Path attribute present
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private boolean hasClassPathAttribute;
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   148
    // true if manifest checked for special attributes
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   149
    private volatile boolean hasCheckedSpecialAttributes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    static {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   152
        // Set up JavaUtilJarAccess in SharedSecrets
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl());
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   154
        // multi-release jar file versions >= 9
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   155
        BASE_VERSION = Runtime.Version.parse(Integer.toString(8));
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   156
        BASE_VERSION_MAJOR = BASE_VERSION.major();
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   157
        String jarVersion = GetPropertyAction.privilegedGetProperty("jdk.util.jar.version");
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37785
diff changeset
   158
        int runtimeVersion = Runtime.version().major();
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   159
        if (jarVersion != null) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   160
            int jarVer = Integer.parseInt(jarVersion);
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   161
            runtimeVersion = (jarVer > runtimeVersion)
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   162
                    ? runtimeVersion
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   163
                    : Math.max(jarVer, BASE_VERSION_MAJOR);
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   164
        }
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   165
        RUNTIME_VERSION = Runtime.Version.parse(Integer.toString(runtimeVersion));
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 37308
diff changeset
   166
        String enableMultiRelease = GetPropertyAction
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
   167
                .privilegedGetProperty("jdk.util.jar.enableMultiRelease", "true");
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   168
        switch (enableMultiRelease) {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   169
            case "true":
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   170
            default:
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   171
                MULTI_RELEASE_ENABLED = true;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   172
                MULTI_RELEASE_FORCED = false;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   173
                break;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   174
            case "false":
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   175
                MULTI_RELEASE_ENABLED = false;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   176
                MULTI_RELEASE_FORCED = false;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   177
                break;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   178
            case "force":
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   179
                MULTI_RELEASE_ENABLED = true;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   180
                MULTI_RELEASE_FORCED = true;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   181
                break;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   182
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   185
    private static final String META_INF = "META-INF/";
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   186
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   187
    private static final String META_INF_VERSIONS = META_INF + "versions/";
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   188
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   189
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * The JAR manifest file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   192
    public static final String MANIFEST_NAME = META_INF + "MANIFEST.MF";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   195
     * The version that represents the unversioned configuration of a multi-release jar file.
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   196
     *
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   197
     * @return Runtime.Version that represents the unversioned configuration
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   198
     *
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   199
     * @since 9
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   200
     */
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   201
    public static Runtime.Version baseVersion() {
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   202
        return BASE_VERSION;
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   203
    }
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   204
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   205
    /**
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   206
     * The version that represents the effective runtime versioned configuration of a
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   207
     * multi-release jar file.  In most cases, {@code runtimeVersion()} is equal to
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   208
     * {@code Runtime.version()}.  However, if the {@code jdk.util.jar.version} property is set,
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   209
     * {@code runtimeVersion()} is derived from that property and may not be equal to
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   210
     * {@code Runtime.version()}.
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   211
     *
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   212
     * @return Runtime.Version that represents the runtime versioned configuration
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   213
     *
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   214
     * @since 9
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   215
     */
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   216
    public static Runtime.Version runtimeVersion() {
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   217
        return RUNTIME_VERSION;
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   218
    }
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   219
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   220
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   221
     * Creates a new {@code JarFile} to read from the specified
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   222
     * file {@code name}. The {@code JarFile} will be verified if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param name the name of the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *         by the SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public JarFile(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        this(new File(name), true, ZipFile.OPEN_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   234
     * Creates a new {@code JarFile} to read from the specified
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   235
     * file {@code name}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param name the name of the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param verify whether or not to verify the jar file if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *         by the SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public JarFile(String name, boolean verify) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        this(new File(name), verify, ZipFile.OPEN_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   248
     * Creates a new {@code JarFile} to read from the specified
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   249
     * {@code File} object. The {@code JarFile} will be verified if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param file the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *         by the SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public JarFile(File file) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        this(file, true, ZipFile.OPEN_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   261
     * Creates a new {@code JarFile} to read from the specified
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   262
     * {@code File} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param file the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param verify whether or not to verify the jar file if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *         by the SecurityManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public JarFile(File file, boolean verify) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        this(file, verify, ZipFile.OPEN_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   275
     * Creates a new {@code JarFile} to read from the specified
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   276
     * {@code File} object in the specified mode.  The mode argument
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   277
     * must be either {@code OPEN_READ} or {@code OPEN_READ | OPEN_DELETE}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param file the jar file to be opened for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param verify whether or not to verify the jar file if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * it is signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param mode the mode in which the file is to be opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @throws IllegalArgumentException
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   285
     *         if the {@code mode} argument is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @throws SecurityException if access to the file is denied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *         by the SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public JarFile(File file, boolean verify, int mode) throws IOException {
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   291
        this(file, verify, mode, BASE_VERSION);
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   292
    }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   293
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   294
    /**
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   295
     * Creates a new {@code JarFile} to read from the specified
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   296
     * {@code File} object in the specified mode.  The mode argument
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   297
     * must be either {@code OPEN_READ} or {@code OPEN_READ | OPEN_DELETE}.
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   298
     * The version argument, after being converted to a canonical form, is
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   299
     * used to configure the {@code JarFile} for processing
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   300
     * multi-release jar files.
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   301
     * <p>
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   302
     * The canonical form derived from the version parameter is
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   303
     * {@code Runtime.Version.parse(Integer.toString(n))} where {@code n} is
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   304
     * {@code Math.max(version.major(), JarFile.baseVersion().major())}.
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   305
     *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   306
     * @param file the jar file to be opened for reading
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   307
     * @param verify whether or not to verify the jar file if
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   308
     * it is signed.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   309
     * @param mode the mode in which the file is to be opened
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   310
     * @param version specifies the release version for a multi-release jar file
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   311
     * @throws IOException if an I/O error has occurred
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   312
     * @throws IllegalArgumentException
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   313
     *         if the {@code mode} argument is invalid
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   314
     * @throws SecurityException if access to the file is denied
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   315
     *         by the SecurityManager
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   316
     * @throws NullPointerException if {@code version} is {@code null}
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   317
     * @since 9
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   318
     */
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   319
    public JarFile(File file, boolean verify, int mode, Runtime.Version version) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        super(file, mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        this.verify = verify;
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   322
        Objects.requireNonNull(version);
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   323
        if (MULTI_RELEASE_FORCED || version.major() == RUNTIME_VERSION.major()) {
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   324
            // This deals with the common case where the value from JarFile.runtimeVersion() is passed
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   325
            this.version = RUNTIME_VERSION;
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   326
        } else if (version.major() <= BASE_VERSION_MAJOR) {
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   327
            // This also deals with the common case where the value from JarFile.baseVersion() is passed
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   328
            this.version = BASE_VERSION;
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   329
        } else {
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   330
            // Canonicalize
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   331
            this.version = Runtime.Version.parse(Integer.toString(version.major()));
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   332
        }
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   333
        this.versionMajor = this.version.major();
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   334
    }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   335
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   336
    /**
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   337
     * Returns the maximum version used when searching for versioned entries.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   338
     *
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   339
     * @return the maximum version
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   340
     * @since 9
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   341
     */
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   342
    public final Runtime.Version getVersion() {
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   343
        return isMultiRelease() ? this.version : BASE_VERSION;
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   344
    }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   345
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   346
    /**
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   347
     * Indicates whether or not this jar file is a multi-release jar file.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   348
     *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   349
     * @return true if this JarFile is a multi-release jar file
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   350
     * @since 9
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   351
     */
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   352
    public final boolean isMultiRelease() {
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   353
        if (isMultiRelease) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   354
            return true;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   355
        }
40539
12bb7768ae6e 8164585: JarFile::isMultiRelease does not return true in all cases where it should return true
sdrach
parents: 39758
diff changeset
   356
        if (MULTI_RELEASE_ENABLED) {
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   357
            try {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   358
                checkForSpecialAttributes();
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   359
            } catch (IOException io) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   360
                isMultiRelease = false;
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   361
            }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   362
        }
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   363
        return isMultiRelease;
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   364
    }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   365
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   367
     * Returns the jar file manifest, or {@code null} if none.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   369
     * @return the jar file manifest, or {@code null} if none
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *         may be thrown if the jar file has been closed
19047
08210fe86260 8021408: Fix misc doclint issues in java.util and java.io
darcy
parents: 18822
diff changeset
   373
     * @throws IOException  if an I/O error has occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public Manifest getManifest() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        return getManifestFromReference();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    private Manifest getManifestFromReference() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        Manifest man = manRef != null ? manRef.get() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (man == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            JarEntry manEntry = getManEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            // If found then load the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (manEntry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                if (verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    byte[] b = getBytes(manEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    man = new Manifest(new ByteArrayInputStream(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    if (!jvInitialized) {
9365
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   392
                        jv = new JarVerifier(b);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    man = new Manifest(super.getInputStream(manEntry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9365
diff changeset
   397
                manRef = new SoftReference<>(man);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
34686
29ea8310a27a 8145260: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk [2]
sherman
parents: 34526
diff changeset
   403
    private String[] getMetaInfEntryNames() {
29ea8310a27a 8145260: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk [2]
sherman
parents: 34526
diff changeset
   404
        return jdk.internal.misc.SharedSecrets.getJavaUtilZipFileAccess()
29ea8310a27a 8145260: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk [2]
sherman
parents: 34526
diff changeset
   405
                                              .getMetaInfEntryNames((ZipFile)this);
29ea8310a27a 8145260: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk [2]
sherman
parents: 34526
diff changeset
   406
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   409
     * Returns the {@code JarEntry} for the given base entry name or
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   410
     * {@code null} if not found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   412
     * <p>If this {@code JarFile} is a multi-release jar file and is configured
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   413
     * to be processed as such, then a search is performed to find and return
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   414
     * a {@code JarEntry} that is the latest versioned entry associated with the
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   415
     * given entry name.  The returned {@code JarEntry} is the versioned entry
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   416
     * corresponding to the given base entry name prefixed with the string
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   417
     * {@code "META-INF/versions/{n}/"}, for the largest value of {@code n} for
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   418
     * which an entry exists.  If such a versioned entry does not exist, then
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   419
     * the {@code JarEntry} for the base entry is returned, otherwise
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   420
     * {@code null} is returned if no entries are found.  The initial value for
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   421
     * the version {@code n} is the maximum version as returned by the method
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   422
     * {@link JarFile#getVersion()}.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   423
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @param name the jar file entry name
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   425
     * @return the {@code JarEntry} for the given entry name, or
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   426
     *         the versioned entry name, or {@code null} if not found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *         may be thrown if the jar file has been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @see java.util.jar.JarEntry
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   432
     *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   433
     * @implSpec
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   434
     * <div class="block">
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   435
     * This implementation invokes {@link JarFile#getEntry(String)}.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   436
     * </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public JarEntry getJarEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return (JarEntry)getEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   443
     * Returns the {@code ZipEntry} for the given base entry name or
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   444
     * {@code null} if not found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   446
     * <p>If this {@code JarFile} is a multi-release jar file and is configured
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   447
     * to be processed as such, then a search is performed to find and return
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   448
     * a {@code ZipEntry} that is the latest versioned entry associated with the
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   449
     * given entry name.  The returned {@code ZipEntry} is the versioned entry
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   450
     * corresponding to the given base entry name prefixed with the string
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   451
     * {@code "META-INF/versions/{n}/"}, for the largest value of {@code n} for
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   452
     * which an entry exists.  If such a versioned entry does not exist, then
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   453
     * the {@code ZipEntry} for the base entry is returned, otherwise
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   454
     * {@code null} is returned if no entries are found.  The initial value for
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   455
     * the version {@code n} is the maximum version as returned by the method
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   456
     * {@link JarFile#getVersion()}.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   457
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param name the jar file entry name
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 31469
diff changeset
   459
     * @return the {@code ZipEntry} for the given entry name or
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   460
     *         the versioned entry name or {@code null} if not found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *         may be thrown if the jar file has been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @see java.util.zip.ZipEntry
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   466
     *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   467
     * @implSpec
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   468
     * <div class="block">
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   469
     * This implementation may return a versioned entry for the requested name
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   470
     * even if there is not a corresponding base entry.  This can occur
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   471
     * if there is a private or package-private versioned entry that matches.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   472
     * If a subclass overrides this method, assure that the override method
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   473
     * invokes {@code super.getEntry(name)} to obtain all versioned entries.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   474
     * </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public ZipEntry getEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        ZipEntry ze = super.getEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (ze != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return new JarFileEntry(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   481
        // no matching base entry, but maybe there is a versioned entry,
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   482
        // like a new private class
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   483
        if (isMultiRelease()) {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   484
            ze = new ZipEntry(name);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   485
            ZipEntry vze = getVersionedEntry(ze);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   486
            if (ze != vze) {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   487
                return new JarFileEntry(name, vze);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   488
            }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   489
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
17421
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   493
    private class JarEntryIterator implements Enumeration<JarEntry>,
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   494
            Iterator<JarEntry>
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   495
    {
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   496
        final Enumeration<? extends ZipEntry> e = JarFile.super.entries();
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   497
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   498
        public boolean hasNext() {
39758
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   499
            return e.hasMoreElements();
17421
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   500
        }
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   501
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   502
        public JarEntry next() {
39758
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   503
            ZipEntry ze = e.nextElement();
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   504
            return new JarFileEntry(ze.getName(), ze);
17421
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   505
        }
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   506
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   507
        public boolean hasMoreElements() {
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   508
            return hasNext();
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   509
        }
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   510
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   511
        public JarEntry nextElement() {
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   512
            return next();
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   513
        }
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 30786
diff changeset
   514
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 30786
diff changeset
   515
        public Iterator<JarEntry> asIterator() {
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 30786
diff changeset
   516
            return this;
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 30786
diff changeset
   517
        }
17421
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   518
    }
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   519
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /**
39758
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   521
     * Returns an enumeration of the jar file entries.
30786
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   522
     *
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   523
     * @return an enumeration of the jar file entries
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   524
     * @throws IllegalStateException
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   525
     *         may be thrown if the jar file has been closed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    public Enumeration<JarEntry> entries() {
17421
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   528
        return new JarEntryIterator();
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   529
    }
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   530
30786
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   531
    /**
39758
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   532
     * Returns an ordered {@code Stream} over the jar file entries.
30786
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   533
     * Entries appear in the {@code Stream} in the order they appear in
39758
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   534
     * the central directory of the jar file.
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   535
     *
30786
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   536
     * @return an ordered {@code Stream} of entries in this jar file
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   537
     * @throws IllegalStateException if the jar file has been closed
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   538
     * @since 1.8
39758
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   539
     *
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   540
     * @apiNote  A versioned view of the stream obtained from a {@code JarFile}
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   541
     * configured to process a multi-release jar file can be created with code
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   542
     * similar to the following:
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   543
     * <pre>
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   544
     * {@code
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   545
     *     Stream<JarEntry> versionedStream(JarFile jf) {
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   546
     *         return jf.stream().map(JarEntry::getName)
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   547
     *                  .filter(name -> !name.startsWith("META-INF/versions/"))
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   548
     *                  .map(jf::getJarEntry);
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   549
     *     }
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   550
     * }
28c2c63fc09f 8157524: Revert JarFile methods "entries" and "stream" to Java 8 behavior
sdrach
parents: 39646
diff changeset
   551
     * </pre>
30786
fb0d6aaea1dc 8064736: Part of java.util.jar.JarFile spec looks confusing with references to Zip
sherman
parents: 29986
diff changeset
   552
     */
17421
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   553
    public Stream<JarEntry> stream() {
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   554
        return StreamSupport.stream(Spliterators.spliterator(
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   555
                new JarEntryIterator(), size(),
f3fbcfe6e2cf 8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile
mduigou
parents: 16117
diff changeset
   556
                Spliterator.ORDERED | Spliterator.DISTINCT |
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17421
diff changeset
   557
                        Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   560
    private ZipEntry searchForVersionedEntry(final int version, String name) {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   561
        ZipEntry vze = null;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   562
        String sname = "/" + name;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   563
        int i = version;
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   564
        while (i > BASE_VERSION_MAJOR) {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   565
            vze = super.getEntry(META_INF_VERSIONS + i + sname);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   566
            if (vze != null) break;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   567
            i--;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   568
        }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   569
        return vze;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   570
    }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   571
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   572
    private ZipEntry getVersionedEntry(ZipEntry ze) {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   573
        ZipEntry vze = null;
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   574
        if (BASE_VERSION_MAJOR < versionMajor && !ze.isDirectory()) {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   575
            String name = ze.getName();
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   576
            if (!name.startsWith(META_INF)) {
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 38432
diff changeset
   577
                vze = searchForVersionedEntry(versionMajor, name);
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   578
            }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   579
        }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   580
        return vze == null ? ze : vze;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   581
    }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   582
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   583
    /**
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   584
     * Returns the real name of a {@code JarEntry}.  If this {@code JarFile} is
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   585
     * a multi-release jar file and is configured to be processed as such, the
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   586
     * name returned by this method is the path name of the versioned entry
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   587
     * that the {@code JarEntry} represents, rather than the path name of the
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   588
     * base entry that {@link JarEntry#getName()} returns.  If the
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   589
     * {@code JarEntry} does not represent a versioned entry, or the
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   590
     * jar file is not a multi-release jar file or {@code JarFile} is not
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   591
     * configured for processing a multi-release jar file, this method returns
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   592
     * the same name that {@link JarEntry#getName()} returns.
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   593
     *
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   594
     * @param entry the JarEntry
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   595
     * @return the real name of the JarEntry
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   596
     * @since 9
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   597
     */
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   598
    String getRealName(JarEntry entry) {
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   599
        if (entry instanceof JarFileEntry) {
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   600
            return ((JarFileEntry)entry).realName();
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   601
        }
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   602
        return entry.getName();
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   603
    }
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   604
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    private class JarFileEntry extends JarEntry {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   606
        final private String name;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   607
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        JarFileEntry(ZipEntry ze) {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   609
            super(isMultiRelease() ? getVersionedEntry(ze) : ze);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   610
            this.name = ze.getName();
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   611
        }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   612
        JarFileEntry(String name, ZipEntry vze) {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   613
            super(vze);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   614
            this.name = name;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        public Attributes getAttributes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            Manifest man = JarFile.this.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            if (man != null) {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   619
                return man.getAttributes(super.getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        public Certificate[] getCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                maybeInstantiateVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (certs == null && jv != null) {
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   631
                certs = jv.getCerts(JarFile.this, realEntry());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            return certs == null ? null : certs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        public CodeSigner[] getCodeSigners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                maybeInstantiateVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            if (signers == null && jv != null) {
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   642
                signers = jv.getCodeSigners(JarFile.this, realEntry());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            return signers == null ? null : signers.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   646
        JarFileEntry realEntry() {
40539
12bb7768ae6e 8164585: JarFile::isMultiRelease does not return true in all cases where it should return true
sdrach
parents: 39758
diff changeset
   647
            if (isMultiRelease() && versionMajor != BASE_VERSION_MAJOR) {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   648
                String entryName = super.getName();
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   649
                return entryName.equals(this.name) ? this : new JarFileEntry(entryName, this);
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   650
            }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   651
            return this;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   652
        }
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   653
        String realName() {
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   654
            return super.getName();
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   655
        }
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   656
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   657
        @Override
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   658
        public String getName() {
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   659
            return name;
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   660
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * Ensures that the JarVerifier has been created if one is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * necessary (i.e., the jar appears to be signed.) This is done as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * a quick check to avoid processing of the manifest for unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * jars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    private void maybeInstantiateVerifier() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        if (jv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            String[] names = getMetaInfEntryNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            if (names != null) {
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   677
                for (String nameLower : names) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   678
                    String name = nameLower.toUpperCase(Locale.ENGLISH);
9365
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   679
                    if (name.endsWith(".DSA") ||
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   680
                        name.endsWith(".RSA") ||
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   681
                        name.endsWith(".EC") ||
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   682
                        name.endsWith(".SF")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                        // Assume since we found a signature-related file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                        // that the jar is signed and that we therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        // need a JarVerifier and Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                        getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            // No signature-related files; don't instantiate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            // verifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            verify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Initializes the verifier object by reading all the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * entries and passing them to the verifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    private void initializeVerifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        ManifestEntryVerifier mev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        // Verify "META-INF/" entries...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            String[] names = getMetaInfEntryNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            if (names != null) {
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   709
                for (String name : names) {
22578
ff8d54ac7c5c 8031572: jarsigner -verify exits with 0 when a jar file is not properly signed
weijun
parents: 22342
diff changeset
   710
                    String uname = name.toUpperCase(Locale.ENGLISH);
ff8d54ac7c5c 8031572: jarsigner -verify exits with 0 when a jar file is not properly signed
weijun
parents: 22342
diff changeset
   711
                    if (MANIFEST_NAME.equals(uname)
ff8d54ac7c5c 8031572: jarsigner -verify exits with 0 when a jar file is not properly signed
weijun
parents: 22342
diff changeset
   712
                            || SignatureFileVerifier.isBlockOrSF(uname)) {
ff8d54ac7c5c 8031572: jarsigner -verify exits with 0 when a jar file is not properly signed
weijun
parents: 22342
diff changeset
   713
                        JarEntry e = getJarEntry(name);
ff8d54ac7c5c 8031572: jarsigner -verify exits with 0 when a jar file is not properly signed
weijun
parents: 22342
diff changeset
   714
                        if (e == null) {
ff8d54ac7c5c 8031572: jarsigner -verify exits with 0 when a jar file is not properly signed
weijun
parents: 22342
diff changeset
   715
                            throw new JarException("corrupted jar file");
ff8d54ac7c5c 8031572: jarsigner -verify exits with 0 when a jar file is not properly signed
weijun
parents: 22342
diff changeset
   716
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                        if (mev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                            mev = new ManifestEntryVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                                (getManifestFromReference());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                        }
9365
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   721
                        byte[] b = getBytes(e);
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   722
                        if (b != null && b.length > 0) {
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   723
                            jv.beginEntry(e, mev);
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   724
                            jv.update(b.length, b, 0, b.length, mev);
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   725
                            jv.update(-1, null, 0, 0, mev);
469cd39a25de 7040803: regression: bugster fail to start
igor
parents: 9248
diff changeset
   726
                        }
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            // if we had an error parsing any blocks, just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            // treat the jar file as being unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            jv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            verify = false;
16082
a042f1412a78 8000210: Improve JarFile code quality
weijun
parents: 11274
diff changeset
   735
            if (JarVerifier.debug != null) {
a042f1412a78 8000210: Improve JarFile code quality
weijun
parents: 11274
diff changeset
   736
                JarVerifier.debug.println("jarfile parsing error!");
a042f1412a78 8000210: Improve JarFile code quality
weijun
parents: 11274
diff changeset
   737
                ex.printStackTrace();
a042f1412a78 8000210: Improve JarFile code quality
weijun
parents: 11274
diff changeset
   738
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        // if after initializing the verifier we have nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        // signed, we null it out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (jv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            jv.doneWithMeta();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            if (JarVerifier.debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                JarVerifier.debug.println("done with meta!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            if (jv.nothingToVerify()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                if (JarVerifier.debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                    JarVerifier.debug.println("nothing to verify!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                jv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                verify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * Reads all the bytes for a given entry. Used to process the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * META-INF files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    private byte[] getBytes(ZipEntry ze) throws IOException {
16082
a042f1412a78 8000210: Improve JarFile code quality
weijun
parents: 11274
diff changeset
   766
        try (InputStream is = super.getInputStream(ze)) {
32933
83d50f1247bb 8138978: Examine usages of sun.misc.IOUtils
chegar
parents: 32834
diff changeset
   767
            int len = (int)ze.getSize();
33235
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   768
            int bytesRead;
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   769
            byte[] b;
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   770
            // trust specified entry sizes when reasonably small
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   771
            if (len != -1 && len <= 65535) {
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   772
                b = new byte[len];
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   773
                bytesRead = is.readNBytes(b, 0, len);
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   774
            } else {
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   775
                b = is.readAllBytes();
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   776
                bytesRead = b.length;
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   777
            }
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   778
            if (len != -1 && len != bytesRead) {
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   779
                throw new EOFException("Expected:" + len + ", read:" + bytesRead);
edfac9a33df3 8139706: JarFile.getBytes could use InputStream.readNBytes
redestad
parents: 32933
diff changeset
   780
            }
32933
83d50f1247bb 8138978: Examine usages of sun.misc.IOUtils
chegar
parents: 32834
diff changeset
   781
            return b;
8553
46c2babb1e44 7021582: convert jar/zip code and tests to use try-with-resources
smarks
parents: 8387
diff changeset
   782
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * Returns an input stream for reading the contents of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * zip file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @param ze the zip file entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @return an input stream for reading the contents of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *         zip file entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @throws ZipException if a zip file format error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @throws IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @throws SecurityException if any of the jar file entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     *         are incorrectly signed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @throws IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *         may be thrown if the jar file has been closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    public synchronized InputStream getInputStream(ZipEntry ze)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        maybeInstantiateVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        if (jv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            return super.getInputStream(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if (!jvInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            initializeVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            jvInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            // could be set to null after a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            // initializeVerifier if we have nothing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            // verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            if (jv == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                return super.getInputStream(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        // wrap a verifier stream around the real stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        return new JarVerifier.VerifierStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            getManifestFromReference(),
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   818
            verifiableEntry(ze),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            super.getInputStream(ze),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            jv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   823
    private JarEntry verifiableEntry(ZipEntry ze) {
36236
eec5770c5b01 8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents: 36219
diff changeset
   824
        if (ze instanceof JarFileEntry) {
eec5770c5b01 8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents: 36219
diff changeset
   825
            // assure the name and entry match for verification
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   826
            return ((JarFileEntry)ze).realEntry();
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   827
        }
36236
eec5770c5b01 8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents: 36219
diff changeset
   828
        ze = getJarEntry(ze.getName());
eec5770c5b01 8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents: 36219
diff changeset
   829
        if (ze instanceof JarFileEntry) {
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   830
            return ((JarFileEntry)ze).realEntry();
36236
eec5770c5b01 8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents: 36219
diff changeset
   831
        }
eec5770c5b01 8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents: 36219
diff changeset
   832
        return (JarEntry)ze;
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   833
    }
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   834
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   835
    // Statics for hand-coded Boyer-Moore search
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   836
    private static final byte[] CLASSPATH_CHARS =
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   837
            {'C','L','A','S','S','-','P','A','T','H', ':', ' '};
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   838
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   839
    // The bad character shift for "class-path:"
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   840
    private static final byte[] CLASSPATH_LASTOCC;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   841
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   842
    private static final byte[] MULTIRELEASE_CHARS =
37308
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   843
            {'M','U','L','T','I','-','R','E','L','E', 'A', 'S', 'E', ':',
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   844
                    ' ', 'T', 'R', 'U', 'E'};
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   845
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   846
    // The bad character shift for "multi-release: "
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   847
    private static final byte[] MULTIRELEASE_LASTOCC;
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   848
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    static {
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   850
        CLASSPATH_LASTOCC = new byte[64];
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   851
        CLASSPATH_LASTOCC[(int)'C' - 32] = 1;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   852
        CLASSPATH_LASTOCC[(int)'L' - 32] = 2;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   853
        CLASSPATH_LASTOCC[(int)'S' - 32] = 5;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   854
        CLASSPATH_LASTOCC[(int)'-' - 32] = 6;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   855
        CLASSPATH_LASTOCC[(int)'P' - 32] = 7;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   856
        CLASSPATH_LASTOCC[(int)'A' - 32] = 8;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   857
        CLASSPATH_LASTOCC[(int)'T' - 32] = 9;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   858
        CLASSPATH_LASTOCC[(int)'H' - 32] = 10;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   859
        CLASSPATH_LASTOCC[(int)':' - 32] = 11;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   860
        CLASSPATH_LASTOCC[(int)' ' - 32] = 12;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   861
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   862
        MULTIRELEASE_LASTOCC = new byte[64];
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   863
        MULTIRELEASE_LASTOCC[(int)'M' - 32] = 1;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   864
        MULTIRELEASE_LASTOCC[(int)'I' - 32] = 5;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   865
        MULTIRELEASE_LASTOCC[(int)'-' - 32] = 6;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   866
        MULTIRELEASE_LASTOCC[(int)'L' - 32] = 9;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   867
        MULTIRELEASE_LASTOCC[(int)'A' - 32] = 11;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   868
        MULTIRELEASE_LASTOCC[(int)'S' - 32] = 12;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   869
        MULTIRELEASE_LASTOCC[(int)':' - 32] = 14;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   870
        MULTIRELEASE_LASTOCC[(int)' ' - 32] = 15;
37308
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   871
        MULTIRELEASE_LASTOCC[(int)'T' - 32] = 16;
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   872
        MULTIRELEASE_LASTOCC[(int)'R' - 32] = 17;
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   873
        MULTIRELEASE_LASTOCC[(int)'U' - 32] = 18;
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   874
        MULTIRELEASE_LASTOCC[(int)'E' - 32] = 19;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    private JarEntry getManEntry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        if (manEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            // First look up manifest entry using standard name
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   880
            ZipEntry manEntry = super.getEntry(MANIFEST_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            if (manEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                // If not found, then iterate through all the "META-INF/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                // entries to find a match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                String[] names = getMetaInfEntryNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                if (names != null) {
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   886
                    for (String name : names) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   887
                        if (MANIFEST_NAME.equals(name.toUpperCase(Locale.ENGLISH))) {
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   888
                            manEntry = super.getEntry(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   894
            this.manEntry = (manEntry == null)
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   895
                    ? null
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 34686
diff changeset
   896
                    : new JarFileEntry(manEntry.getName(), manEntry);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        return manEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   901
   /**
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   902
    * Returns {@code true} iff this JAR file has a manifest with the
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   903
    * Class-Path attribute
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   904
    */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    boolean hasClassPathAttribute() throws IOException {
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   906
        checkForSpecialAttributes();
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   907
        return hasClassPathAttribute;
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   908
    }
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   909
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   910
    /**
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   911
     * Returns true if the pattern {@code src} is found in {@code b}.
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   912
     * The {@code lastOcc} array is the precomputed bad character shifts.
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   913
     * Since there are no repeated substring in our search strings,
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   914
     * the good suffix shifts can be replaced with a comparison.
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   915
     */
37308
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   916
    private int match(byte[] src, byte[] b, byte[] lastOcc) {
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   917
        int len = src.length;
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   918
        int last = b.length - len;
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   919
        int i = 0;
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   920
        next:
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   921
        while (i <= last) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   922
            for (int j = (len - 1); j >= 0; j--) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   923
                byte c = b[i + j];
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   924
                if (c >= ' ' && c <= 'z') {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   925
                    if (c >= 'a') c -= 32; // Canonicalize
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   926
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   927
                    if (c != src[j]) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   928
                        // no match
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   929
                        int goodShift = (j < len - 1) ? len : 1;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   930
                        int badShift = lastOcc[c - 32];
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   931
                        i += Math.max(j + 1 - badShift, goodShift);
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   932
                        continue next;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   933
                    }
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   934
                } else {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   935
                    // no match, character not valid for name
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   936
                    i += len;
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   937
                    continue next;
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   938
                }
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   939
            }
37308
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   940
            return i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
37308
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   942
        return -1;
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   943
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   945
    /**
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   946
     * On first invocation, check if the JAR file has the Class-Path
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   947
     * and the Multi-Release attribute. A no-op on subsequent calls.
16023
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   948
     */
58ecc1b8327b 8008290: (profiles) Startup regression due to additional checking of JAR file manifests
alanb
parents: 11274
diff changeset
   949
    private void checkForSpecialAttributes() throws IOException {
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   950
        if (hasCheckedSpecialAttributes) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   951
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        }
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   953
        synchronized (this) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   954
            if (hasCheckedSpecialAttributes) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   955
                return;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   956
            }
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   957
            JarEntry manEntry = getManEntry();
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   958
            if (manEntry != null) {
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   959
                byte[] b = getBytes(manEntry);
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   960
                hasClassPathAttribute = match(CLASSPATH_CHARS, b,
37308
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   961
                        CLASSPATH_LASTOCC) != -1;
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   962
                // is this a multi-release jar file
40539
12bb7768ae6e 8164585: JarFile::isMultiRelease does not return true in all cases where it should return true
sdrach
parents: 39758
diff changeset
   963
                if (MULTI_RELEASE_ENABLED) {
37308
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   964
                    int i = match(MULTIRELEASE_CHARS, b, MULTIRELEASE_LASTOCC);
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   965
                    if (i != -1) {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   966
                        i += MULTIRELEASE_CHARS.length;
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   967
                        if (i < b.length) {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   968
                            byte c = b[i++];
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   969
                            // Check that the value is followed by a newline
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   970
                            // and does not have a continuation
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   971
                            if (c == '\n' &&
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   972
                                    (i == b.length || b[i] != ' ')) {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   973
                                isMultiRelease = true;
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   974
                            } else if (c == '\r') {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   975
                                if (i == b.length) {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   976
                                    isMultiRelease = true;
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   977
                                } else {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   978
                                    c = b[i++];
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   979
                                    if (c == '\n') {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   980
                                        if (i == b.length || b[i] != ' ') {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   981
                                            isMultiRelease = true;
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   982
                                        }
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   983
                                    } else if (c != ' ') {
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   984
                                        isMultiRelease = true;
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   985
                                    }
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   986
                                }
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   987
                            }
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   988
                        }
4c4141aac146 8153213: Jar manifest attribute "Multi-Release" accepts any value
redestad
parents: 36734
diff changeset
   989
                    }
36734
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   990
                }
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   991
            }
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   992
            hasCheckedSpecialAttributes = true;
18c3da127b06 8152733: Avoid creating Manifest when checking for Multi-Release attribute
redestad
parents: 36236
diff changeset
   993
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
   996
    private synchronized void ensureInitialization() {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
   997
        try {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
   998
            maybeInstantiateVerifier();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
   999
        } catch (IOException e) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1000
            throw new RuntimeException(e);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1001
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1002
        if (jv != null && !jvInitialized) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1003
            initializeVerifier();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1004
            jvInitialized = true;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1005
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1006
    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1007
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1008
    JarEntry newEntry(ZipEntry ze) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1009
        return new JarFileEntry(ze);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1010
    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1011
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1012
    Enumeration<String> entryNames(CodeSource[] cs) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1013
        ensureInitialization();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1014
        if (jv != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1015
            return jv.entryNames(this, cs);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1016
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1017
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1018
        /*
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1019
         * JAR file has no signed content. Is there a non-signing
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1020
         * code source?
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1021
         */
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1022
        boolean includeUnsigned = false;
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
  1023
        for (CodeSource c : cs) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
  1024
            if (c.getCodeSigners() == null) {
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1025
                includeUnsigned = true;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1026
                break;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1027
            }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1028
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1029
        if (includeUnsigned) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1030
            return unsignedEntryNames();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1031
        } else {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27565
diff changeset
  1032
            return new Enumeration<>() {
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1033
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1034
                public boolean hasMoreElements() {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1035
                    return false;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1036
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1037
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1038
                public String nextElement() {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1039
                    throw new NoSuchElementException();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1040
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1041
            };
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1042
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1043
    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1044
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1045
    /**
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1046
     * Returns an enumeration of the zip file entries
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1047
     * excluding internal JAR mechanism entries and including
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1048
     * signed entries missing from the ZIP directory.
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1049
     */
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1050
    Enumeration<JarEntry> entries2() {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1051
        ensureInitialization();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1052
        if (jv != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1053
            return jv.entries2(this, super.entries());
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1054
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1055
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1056
        // screen out entries which are never signed
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9365
diff changeset
  1057
        final Enumeration<? extends ZipEntry> enum_ = super.entries();
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27565
diff changeset
  1058
        return new Enumeration<>() {
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1059
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1060
            ZipEntry entry;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1061
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1062
            public boolean hasMoreElements() {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1063
                if (entry != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1064
                    return true;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1065
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1066
                while (enum_.hasMoreElements()) {
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9365
diff changeset
  1067
                    ZipEntry ze = enum_.nextElement();
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1068
                    if (JarVerifier.isSigningRelated(ze.getName())) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1069
                        continue;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1070
                    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1071
                    entry = ze;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1072
                    return true;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1073
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1074
                return false;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1075
            }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1076
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1077
            public JarFileEntry nextElement() {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1078
                if (hasMoreElements()) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1079
                    ZipEntry ze = entry;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1080
                    entry = null;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1081
                    return new JarFileEntry(ze);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1082
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1083
                throw new NoSuchElementException();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1084
            }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1085
        };
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1086
    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1087
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1088
    CodeSource[] getCodeSources(URL url) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1089
        ensureInitialization();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1090
        if (jv != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1091
            return jv.getCodeSources(this, url);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1092
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1093
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1094
        /*
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1095
         * JAR file has no signed content. Is there a non-signing
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1096
         * code source?
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1097
         */
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9365
diff changeset
  1098
        Enumeration<String> unsigned = unsignedEntryNames();
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1099
        if (unsigned.hasMoreElements()) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1100
            return new CodeSource[]{JarVerifier.getUnsignedCS(url)};
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1101
        } else {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1102
            return null;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1103
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1104
    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1105
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1106
    private Enumeration<String> unsignedEntryNames() {
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9365
diff changeset
  1107
        final Enumeration<JarEntry> entries = entries();
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27565
diff changeset
  1108
        return new Enumeration<>() {
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1109
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1110
            String name;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1111
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1112
            /*
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1113
             * Grab entries from ZIP directory but screen out
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1114
             * metadata.
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1115
             */
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1116
            public boolean hasMoreElements() {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1117
                if (name != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1118
                    return true;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1119
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1120
                while (entries.hasMoreElements()) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1121
                    String value;
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9365
diff changeset
  1122
                    ZipEntry e = entries.nextElement();
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1123
                    value = e.getName();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1124
                    if (e.isDirectory() || JarVerifier.isSigningRelated(value)) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1125
                        continue;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1126
                    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1127
                    name = value;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1128
                    return true;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1129
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1130
                return false;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1131
            }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1132
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1133
            public String nextElement() {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1134
                if (hasMoreElements()) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1135
                    String value = name;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1136
                    name = null;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1137
                    return value;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1138
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1139
                throw new NoSuchElementException();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1140
            }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1141
        };
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1142
    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1143
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1144
    CodeSource getCodeSource(URL url, String name) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1145
        ensureInitialization();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1146
        if (jv != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1147
            if (jv.eagerValidation) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1148
                CodeSource cs = null;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1149
                JarEntry je = getJarEntry(name);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1150
                if (je != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1151
                    cs = jv.getCodeSource(url, this, je);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1152
                } else {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1153
                    cs = jv.getCodeSource(url, name);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1154
                }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1155
                return cs;
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1156
            } else {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1157
                return jv.getCodeSource(url, name);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1158
            }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1159
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1160
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1161
        return JarVerifier.getUnsignedCS(url);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1162
    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1163
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1164
    void setEagerValidation(boolean eager) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1165
        try {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1166
            maybeInstantiateVerifier();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1167
        } catch (IOException e) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1168
            throw new RuntimeException(e);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1169
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1170
        if (jv != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1171
            jv.setEagerValidation(eager);
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1172
        }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1173
    }
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1174
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 9365
diff changeset
  1175
    List<Object> getManifestDigests() {
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1176
        ensureInitialization();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1177
        if (jv != null) {
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1178
            return jv.getManifestDigests();
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1179
        }
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
  1180
        return new ArrayList<>();
8387
f0fa7bbf889e 6742654: Code insertion/replacement attacks against signed jars
weijun
parents: 5506
diff changeset
  1181
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
}