jdk/src/java.base/share/classes/java/lang/Package.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 29986 97167d851fc4
child 36511 9d0388c6b336
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15534
19228f4aedb4 8007113: Upgrade AnnotatedElement.isAnnotionPresent to be a default method
darcy
parents: 14676
diff changeset
     2
 * Copyright (c) 1997, 2013, 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: 3959
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: 3959
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: 3959
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
16051
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
    28
import java.lang.reflect.AnnotatedElement;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
    38
import java.util.concurrent.ConcurrentHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.jar.JarInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.jar.Manifest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.jar.Attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.jar.Attributes.Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.net.www.ParseUtil;
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
    46
import sun.reflect.CallerSensitive;
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
    47
import sun.reflect.Reflection;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.lang.annotation.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@code Package} objects contain version information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * about the implementation and specification of a Java package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * This versioning information is retrieved and made available
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * by the {@link ClassLoader} instance that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * loaded the class(es).  Typically, it is stored in the manifest that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * distributed with the classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>The set of classes that make up the package may implement a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * particular specification and if so the specification title, version number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * and vendor strings identify that specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * An application can ask if the package is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * compatible with a particular version, see the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * #isCompatibleWith isCompatibleWith}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * method for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>Specification version numbers use a syntax that consists of nonnegative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * decimal integers separated by periods ".", for example "2.0" or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * "1.2.3.4.5.6.7".  This allows an extensible number to be used to represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * major, minor, micro, etc. versions.  The version specification is described
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * by the following formal grammar:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <dl>
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
    74
 * <dt><i>SpecificationVersion:</i>
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
    75
 * <dd><i>Digits RefinedVersion<sub>opt</sub></i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
    77
 * <dt><i>RefinedVersion:</i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <dd>{@code .} <i>Digits</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <dd>{@code .} <i>Digits RefinedVersion</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
    81
 * <dt><i>Digits:</i>
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
    82
 * <dd><i>Digit</i>
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
    83
 * <dd><i>Digits</i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
    85
 * <dt><i>Digit:</i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <dd>any character for which {@link Character#isDigit} returns {@code true},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * e.g. 0, 1, 2, ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>The implementation title, version, and vendor strings identify an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * implementation and are made available conveniently to enable accurate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * reporting of the packages involved when a problem occurs. The contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * all three implementation strings are vendor specific. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * implementation version strings have no specified syntax and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * only be compared for equality with desired version identifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <p>Within each {@code ClassLoader} instance all classes from the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * java package have the same Package object.  The static methods allow a package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * to be found by name or the set of all packages known to the current class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * loader to be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @see ClassLoader#definePackage
25176
3c2ba9344cbf 8047721: @since should have JDK version
henryjen
parents: 22581
diff changeset
   104
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
public class Package implements java.lang.reflect.AnnotatedElement {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Return the name of this package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   110
     * @return  The fully-qualified name of this package as defined in section 6.5.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   111
     *          <cite>The Java&trade; Language Specification</cite>,
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   112
     *          for example, {@code java.lang}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return pkgName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Return the title of the specification that this package implements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return the specification title, null is returned if it is not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public String getSpecificationTitle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return specTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Returns the version number of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * that this package implements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * This version string must be a sequence of nonnegative decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * integers separated by "."'s and may have leading zeros.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * When version strings are compared the most significant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * numbers are compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return the specification version, null is returned if it is not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public String getSpecificationVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return specVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Return the name of the organization, vendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * or company that owns and maintains the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * of the classes that implement this package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return the specification vendor, null is returned if it is not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public String getSpecificationVendor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return specVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Return the title of this package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the title of the implementation, null is returned if it is not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public String getImplementationTitle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return implTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Return the version of this implementation. It consists of any string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * assigned by the vendor of this implementation and does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * not have any particular syntax specified or expected by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * runtime. It may be compared for equality with other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * package version strings used for this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * by this vendor for this package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return the version of the implementation, null is returned if it is not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public String getImplementationVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return implVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns the name of the organization,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * vendor or company that provided this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @return the vendor that implemented this package..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public String getImplementationVendor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return implVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Returns true if this package is sealed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return true if the package is sealed, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public boolean isSealed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return sealBase != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns true if this package is sealed with respect to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * code source url.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param url the code source url
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @return true if this package is sealed with respect to url
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public boolean isSealed(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return url.equals(sealBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Compare this package's specification version with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * desired version. It returns true if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * this packages specification version number is greater than or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * to the desired version number. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Version numbers are compared by sequentially comparing corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * components of the desired and specification strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Each component is converted as a decimal integer and the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * If the specification value is greater than the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * value true is returned. If the value is less false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * If the values are equal the period is skipped and the next pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * components is compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param desired the version string of the desired version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return true if this package's version number is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *          than or equal to the desired version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @exception NumberFormatException if the desired or current version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *          is not of the correct dotted form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public boolean isCompatibleWith(String desired)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        throws NumberFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (specVersion == null || specVersion.length() < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            throw new NumberFormatException("Empty version string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        String [] sa = specVersion.split("\\.", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        int [] si = new int[sa.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        for (int i = 0; i < sa.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            si[i] = Integer.parseInt(sa[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            if (si[i] < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                throw NumberFormatException.forInputString("" + si[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        String [] da = desired.split("\\.", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        int [] di = new int[da.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        for (int i = 0; i < da.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            di[i] = Integer.parseInt(da[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (di[i] < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                throw NumberFormatException.forInputString("" + di[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        int len = Math.max(di.length, si.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            int d = (i < di.length ? di[i] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            int s = (i < si.length ? si[i] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (s < d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if (s > d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Find a package by name in the callers {@code ClassLoader} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * The callers {@code ClassLoader} instance is used to find the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * instance corresponding to the named class. If the callers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * {@code ClassLoader} instance is null then the set of packages loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * by the system {@code ClassLoader} instance is searched to find the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * named package. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Packages have attributes for versions and specifications only if the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * loader created the package instance with the appropriate attributes. Typically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * those attributes are defined in the manifests that accompany the classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param name a package name, for example, java.lang.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @return the package of the requested name. It may be null if no package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *          information is available from the archive or codebase.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   273
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public static Package getPackage(String name) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   275
        ClassLoader l = ClassLoader.getClassLoader(Reflection.getCallerClass());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (l != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return l.getPackage(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return getSystemPackage(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Get all the packages currently known for the caller's {@code ClassLoader}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * instance.  Those packages correspond to classes loaded via or accessible by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * name to that {@code ClassLoader} instance.  If the caller's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * {@code ClassLoader} instance is the bootstrap {@code ClassLoader}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * instance, which may be represented by {@code null} in some implementations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * only packages corresponding to classes loaded by the bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * {@code ClassLoader} instance will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @return a new array of packages known to the callers {@code ClassLoader}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * instance.  An zero length array is returned if none are known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   295
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public static Package[] getPackages() {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   297
        ClassLoader l = ClassLoader.getClassLoader(Reflection.getCallerClass());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (l != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            return l.getPackages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return getSystemPackages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Get the package for the specified class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * The class's class loader is used to find the package instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * corresponding to the specified class. If the class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * is the bootstrap class loader, which may be represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * {@code null} in some implementations, then the set of packages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * loaded by the bootstrap class loader is searched to find the package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Packages have attributes for versions and specifications only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * if the class loader created the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * instance with the appropriate attributes. Typically those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * attributes are defined in the manifests that accompany
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * the classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 11117
diff changeset
   319
     * @param c the class to get the package of.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @return the package of the class. It may be null if no package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *          information is available from the archive or codebase.  */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 715
diff changeset
   322
    static Package getPackage(Class<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        String name = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        int i = name.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (i != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            name = name.substring(0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            ClassLoader cl = c.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                return cl.getPackage(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                return getSystemPackage(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Return the hash code computed from the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @return the hash code computed from the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public int hashCode(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return pkgName.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * Returns the string representation of this Package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Its value is the string "package " and the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * If the package title is defined it is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * If the package version is defined it is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @return the string representation of the package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        String spec = specTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        String ver =  specVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (spec != null && spec.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            spec = ", " + spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            spec = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if (ver != null && ver.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            ver = ", version " + ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            ver = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return "package " + pkgName + spec + ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private Class<?> getPackageInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (packageInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                packageInfo = Class.forName(pkgName + ".package-info", false, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            } catch (ClassNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                // store a proxy for the package info that has no annotations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                class PackageInfoProxy {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                packageInfo = PackageInfoProxy.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return packageInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return getPackageInfo().getAnnotation(annotationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
16051
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   389
     * {@inheritDoc}
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   390
     * @throws NullPointerException {@inheritDoc}
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   391
     * @since 1.5
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   392
     */
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   393
    @Override
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   394
    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   395
        return AnnotatedElement.super.isAnnotationPresent(annotationClass);
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   396
    }
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   397
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   398
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @throws NullPointerException {@inheritDoc}
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   400
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   401
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   402
    @Override
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   403
    public  <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) {
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   404
        return getPackageInfo().getAnnotationsByType(annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   405
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   406
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   407
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public Annotation[] getAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return getPackageInfo().getAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    /**
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   415
     * @throws NullPointerException {@inheritDoc}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   416
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   417
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   418
    @Override
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   419
    public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass) {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   420
        return getPackageInfo().getDeclaredAnnotation(annotationClass);
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   421
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   422
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   423
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   424
     * @throws NullPointerException {@inheritDoc}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   425
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   426
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   427
    @Override
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   428
    public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationClass) {
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   429
        return getPackageInfo().getDeclaredAnnotationsByType(annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   430
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   431
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   432
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public Annotation[] getDeclaredAnnotations()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return getPackageInfo().getDeclaredAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Construct a package instance with the specified version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * information.
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 11117
diff changeset
   442
     * @param name the name of the package
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @param spectitle the title of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @param specversion the version of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @param specvendor the organization that maintains the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param impltitle the title of the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param implversion the version of the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @param implvendor the organization that maintains the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    Package(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            String spectitle, String specversion, String specvendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            String impltitle, String implversion, String implvendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            URL sealbase, ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        pkgName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        implTitle = impltitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        implVersion = implversion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        implVendor = implvendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        specTitle = spectitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        specVersion = specversion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        specVendor = specvendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        sealBase = sealbase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        this.loader = loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * Construct a package using the attributes from the specified manifest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @param name the package name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @param man the optional manifest for the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @param url the optional code source url for the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    private Package(String name, Manifest man, URL url, ClassLoader loader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        String path = name.replace('.', '/').concat("/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        String sealed = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        String specTitle= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        String specVersion= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        String specVendor= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        String implTitle= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        String implVersion= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        String implVendor= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        URL sealBase= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        Attributes attr = man.getAttributes(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            specTitle   = attr.getValue(Name.SPECIFICATION_TITLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            specVendor  = attr.getValue(Name.SPECIFICATION_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            implTitle   = attr.getValue(Name.IMPLEMENTATION_TITLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            implVendor  = attr.getValue(Name.IMPLEMENTATION_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            sealed      = attr.getValue(Name.SEALED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        attr = man.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            if (specTitle == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            if (specVersion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            if (specVendor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            if (implTitle == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if (implVersion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            if (implVendor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (sealed == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                sealed = attr.getValue(Name.SEALED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if ("true".equalsIgnoreCase(sealed)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            sealBase = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        pkgName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        this.specTitle = specTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        this.specVersion = specVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        this.specVendor = specVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        this.implTitle = implTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        this.implVersion = implVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        this.implVendor = implVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        this.sealBase = sealBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        this.loader = loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Returns the loaded system package for the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    static Package getSystemPackage(String name) {
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   535
        Package pkg = pkgs.get(name);
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   536
        if (pkg == null) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   537
            name = name.replace('.', '/').concat("/");
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   538
            String fn = getSystemPackage0(name);
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   539
            if (fn != null) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   540
                pkg = defineSystemPackage(name, fn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   543
        return pkg;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * Return an array of loaded system packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    static Package[] getSystemPackages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        // First, update the system package map with new package names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        String[] names = getSystemPackages0();
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   552
        for (String name : names) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   553
            if (!pkgs.containsKey(name)) {
22581
e868cde95050 8032779: Update code in java.lang to use newer language features
psandoz
parents: 18546
diff changeset
   554
                defineSystemPackage(name, getSystemPackage0(name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   557
        return pkgs.values().toArray(new Package[pkgs.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    private static Package defineSystemPackage(final String iname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                               final String fn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    {
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   563
        // Convert to "."-separated package name
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   564
        String name = iname.substring(0, iname.length() - 1).replace('/', '.');
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   565
        // Creates a cached manifest for the file name, allowing
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   566
        // only-once, lazy reads of manifest from jar files
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   567
        CachedManifest cachedManifest = createCachedManifest(fn);
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   568
        pkgs.putIfAbsent(name, new Package(name, cachedManifest.getManifest(),
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   569
                                           cachedManifest.getURL(), null));
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   570
        // Ensure we only expose one Package object
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   571
        return pkgs.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   574
    private static CachedManifest createCachedManifest(String fn) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   575
        if (!manifests.containsKey(fn)) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   576
            manifests.putIfAbsent(fn, new CachedManifest(fn));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   578
        return manifests.get(fn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    // The map of loaded system packages
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   582
    private static final ConcurrentHashMap<String, Package> pkgs
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   583
            = new ConcurrentHashMap<>();
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   584
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   585
    // Maps each directory or zip file name to its corresponding manifest, if
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   586
    // it exists
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   587
    private static final ConcurrentHashMap<String, CachedManifest> manifests
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   588
            = new ConcurrentHashMap<>();
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   589
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   590
    private static class CachedManifest {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   591
        private static final Manifest EMPTY_MANIFEST = new Manifest();
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   592
        private final String fileName;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   593
        private final URL url;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   594
        private volatile Manifest manifest;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   595
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   596
        CachedManifest(final String fileName) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   597
            this.fileName = fileName;
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27348
diff changeset
   598
            this.url = AccessController.doPrivileged(new PrivilegedAction<>() {
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   599
                public URL run() {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   600
                    final File file = new File(fileName);
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   601
                    if (file.isFile()) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   602
                        try {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   603
                            return ParseUtil.fileToEncodedURL(file);
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   604
                        } catch (MalformedURLException e) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   605
                        }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   606
                    }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   607
                    return null;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   608
                }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   609
            });
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   610
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   612
        public URL getURL() {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   613
            return url;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   614
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   616
        public Manifest getManifest() {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   617
            if (url == null) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   618
                return EMPTY_MANIFEST;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   619
            }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   620
            Manifest m = manifest;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   621
            if (m != null) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   622
                return m;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   623
            }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   624
            synchronized (this) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   625
                m = manifest;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   626
                if (m != null) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   627
                    return m;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   628
                }
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27348
diff changeset
   629
                m = AccessController.doPrivileged(new PrivilegedAction<>() {
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   630
                    public Manifest run() {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   631
                        try (FileInputStream fis = new FileInputStream(fileName);
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   632
                             JarInputStream jis = new JarInputStream(fis, false)) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   633
                            return jis.getManifest();
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   634
                        } catch (IOException e) {
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   635
                            return null;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   636
                        }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   637
                    }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   638
                });
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   639
                manifest = m = (m == null ? EMPTY_MANIFEST : m);
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   640
            }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   641
            return m;
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   642
        }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   643
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    private static native String getSystemPackage0(String name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    private static native String[] getSystemPackages0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * Private storage for the package name and attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    private final String pkgName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    private final String specTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    private final String specVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    private final String specVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    private final String implTitle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    private final String implVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    private final String implVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    private final URL sealBase;
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 29986
diff changeset
   659
    private final transient ClassLoader loader;
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 9275
diff changeset
   660
    private transient Class<?> packageInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
}