jdk/src/share/classes/java/net/URLClassLoader.java
author juh
Tue, 30 Jul 2013 11:04:19 -0700
changeset 19069 1d9cb0d080e3
parent 15682 793a36de151d
child 19409 d7c7b9d56631
permissions -rw-r--r--
8021833: javadoc cleanup in java.net Summary: <code> and <tt> converted to {@code }; package.html to package-info.java Reviewed-by: darcy, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
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: 3849
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: 3849
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: 3849
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3849
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3849
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.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
    28
import java.io.*;
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
    29
import java.util.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.jar.Manifest;
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
    31
import java.util.jar.JarFile;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.jar.Attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.jar.Attributes.Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.CodeSigner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.AccessControlContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.SecureClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.CodeSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.PermissionCollection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.misc.Resource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.misc.URLClassPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.net.www.ParseUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * This class loader is used to load classes and resources from a search
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * path of URLs referring to both JAR files and directories. Any URL that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * ends with a '/' is assumed to refer to a directory. Otherwise, the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * is assumed to refer to a JAR file which will be opened as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The AccessControlContext of the thread that created the instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * URLClassLoader will be used when subsequently loading classes and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * The classes that are loaded are by default granted permission only to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * access the URLs specified when the URLClassLoader was created.
15682
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 10596
diff changeset
    60
 * <p>
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 10596
diff changeset
    61
 * Where a JAR file contains the {@link Name#PROFILE Profile} attribute
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 10596
diff changeset
    62
 * then its value is the name of the Java SE profile that the library
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 10596
diff changeset
    63
 * minimally requires. If this runtime does not support the profile then
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 10596
diff changeset
    64
 * it causes {@link java.util.jar.UnsupportedProfileException} to be
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 10596
diff changeset
    65
 * thrown at some unspecified time.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author  David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
    70
public class URLClassLoader extends SecureClassLoader implements Closeable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /* The search path for classes and resources */
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
    72
    private final URLClassPath ucp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /* The context to be used when loading classes and resources */
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
    75
    private final AccessControlContext acc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Constructs a new URLClassLoader for the given URLs. The URLs will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * searched in the order specified for classes and resources after first
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * searching in the specified parent class loader. Any URL that ends with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * a '/' is assumed to refer to a directory. Otherwise, the URL is assumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * to refer to a JAR file which will be downloaded and opened as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * <p>If there is a security manager, this method first
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
    85
     * calls the security manager's {@code checkCreateClassLoader} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * to ensure creation of a class loader is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param urls the URLs from which to load classes and resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param parent the parent class loader for delegation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @exception  SecurityException  if a security manager exists and its
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
    91
     *             {@code checkCreateClassLoader} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *             creation of a class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @see SecurityManager#checkCreateClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public URLClassLoader(URL[] urls, ClassLoader parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        // this is to make the stack depth consistent with 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            security.checkCreateClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        ucp = new URLClassPath(urls);
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   103
        this.acc = AccessController.getContext();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   104
    }
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   105
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   106
    URLClassLoader(URL[] urls, ClassLoader parent,
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   107
                   AccessControlContext acc) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   108
        super(parent);
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   109
        // this is to make the stack depth consistent with 1.1
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   110
        SecurityManager security = System.getSecurityManager();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   111
        if (security != null) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   112
            security.checkCreateClassLoader();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   113
        }
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   114
        ucp = new URLClassPath(urls);
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   115
        this.acc = acc;
2
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
     * Constructs a new URLClassLoader for the specified URLs using the
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   120
     * default delegation parent {@code ClassLoader}. The URLs will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * be searched in the order specified for classes and resources after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * first searching in the parent class loader. Any URL that ends with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * a '/' is assumed to refer to a directory. Otherwise, the URL is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * assumed to refer to a JAR file which will be downloaded and opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <p>If there is a security manager, this method first
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   128
     * calls the security manager's {@code checkCreateClassLoader} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * to ensure creation of a class loader is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param urls the URLs from which to load classes and resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @exception  SecurityException  if a security manager exists and its
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   134
     *             {@code checkCreateClassLoader} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *             creation of a class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see SecurityManager#checkCreateClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public URLClassLoader(URL[] urls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // this is to make the stack depth consistent with 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            security.checkCreateClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        ucp = new URLClassPath(urls);
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   146
        this.acc = AccessController.getContext();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   147
    }
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   148
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   149
    URLClassLoader(URL[] urls, AccessControlContext acc) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   150
        super();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   151
        // this is to make the stack depth consistent with 1.1
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   152
        SecurityManager security = System.getSecurityManager();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   153
        if (security != null) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   154
            security.checkCreateClassLoader();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   155
        }
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   156
        ucp = new URLClassPath(urls);
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   157
        this.acc = acc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Constructs a new URLClassLoader for the specified URLs, parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * class loader, and URLStreamHandlerFactory. The parent argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * will be used as the parent class loader for delegation. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * factory argument will be used as the stream handler factory to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * obtain protocol handlers when creating new jar URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <p>If there is a security manager, this method first
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   168
     * calls the security manager's {@code checkCreateClassLoader} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * to ensure creation of a class loader is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param urls the URLs from which to load classes and resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param parent the parent class loader for delegation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param factory the URLStreamHandlerFactory to use when creating URLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @exception  SecurityException  if a security manager exists and its
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   176
     *             {@code checkCreateClassLoader} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *             creation of a class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see SecurityManager#checkCreateClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public URLClassLoader(URL[] urls, ClassLoader parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                          URLStreamHandlerFactory factory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        super(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        // this is to make the stack depth consistent with 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            security.checkCreateClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        ucp = new URLClassPath(urls, factory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        acc = AccessController.getContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   192
    /* A map (used as a set) to keep track of closeable local resources
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   193
     * (either JarFiles or FileInputStreams). We don't care about
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   194
     * Http resources since they don't need to be closed.
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   195
     *
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   196
     * If the resource is coming from a jar file
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   197
     * we keep a (weak) reference to the JarFile object which can
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   198
     * be closed if URLClassLoader.close() called. Due to jar file
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   199
     * caching there will typically be only one JarFile object
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   200
     * per underlying jar file.
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   201
     *
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   202
     * For file resources, which is probably a less common situation
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   203
     * we have to keep a weak reference to each stream.
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   204
     */
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   205
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   206
    private WeakHashMap<Closeable,Void>
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   207
        closeables = new WeakHashMap<>();
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   208
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   209
    /**
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   210
     * Returns an input stream for reading the specified resource.
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   211
     * If this loader is closed, then any resources opened by this method
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   212
     * will be closed.
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   213
     *
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   214
     * <p> The search order is described in the documentation for {@link
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   215
     * #getResource(String)}.  </p>
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   216
     *
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   217
     * @param  name
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   218
     *         The resource name
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   219
     *
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   220
     * @return  An input stream for reading the resource, or {@code null}
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   221
     *          if the resource could not be found
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   222
     *
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   223
     * @since  1.7
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   224
     */
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   225
    public InputStream getResourceAsStream(String name) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   226
        URL url = getResource(name);
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   227
        try {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   228
            if (url == null) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   229
                return null;
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   230
            }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   231
            URLConnection urlc = url.openConnection();
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   232
            InputStream is = urlc.getInputStream();
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   233
            if (urlc instanceof JarURLConnection) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   234
                JarURLConnection juc = (JarURLConnection)urlc;
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   235
                JarFile jar = juc.getJarFile();
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   236
                synchronized (closeables) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   237
                    if (!closeables.containsKey(jar)) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   238
                        closeables.put(jar, null);
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   239
                    }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   240
                }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   241
            } else if (urlc instanceof sun.net.www.protocol.file.FileURLConnection) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   242
                synchronized (closeables) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   243
                    closeables.put(is, null);
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   244
                }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   245
            }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   246
            return is;
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   247
        } catch (IOException e) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   248
            return null;
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   249
        }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   250
    }
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   251
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   252
   /**
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   253
    * Closes this URLClassLoader, so that it can no longer be used to load
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   254
    * new classes or resources that are defined by this loader.
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   255
    * Classes and resources defined by any of this loader's parents in the
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   256
    * delegation hierarchy are still accessible. Also, any classes or resources
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   257
    * that are already loaded, are still accessible.
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   258
    * <p>
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   259
    * In the case of jar: and file: URLs, it also closes any files
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   260
    * that were opened by it. If another thread is loading a
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   261
    * class when the {@code close} method is invoked, then the result of
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   262
    * that load is undefined.
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   263
    * <p>
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   264
    * The method makes a best effort attempt to close all opened files,
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   265
    * by catching {@link IOException}s internally. Unchecked exceptions
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   266
    * and errors are not caught. Calling close on an already closed
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   267
    * loader has no effect.
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   268
    * <p>
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   269
    * @throws IOException if closing any file opened by this class loader
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   270
    * resulted in an IOException. Any such exceptions are caught internally.
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   271
    * If only one is caught, then it is re-thrown. If more than one exception
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   272
    * is caught, then the second and following exceptions are added
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   273
    * as suppressed exceptions of the first one caught, which is then re-thrown.
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   274
    *
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   275
    * @throws SecurityException if a security manager is set, and it denies
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   276
    *   {@link RuntimePermission}{@code ("closeClassLoader")}
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   277
    *
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   278
    * @since 1.7
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   279
    */
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   280
    public void close() throws IOException {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   281
        SecurityManager security = System.getSecurityManager();
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   282
        if (security != null) {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   283
            security.checkPermission(new RuntimePermission("closeClassLoader"));
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   284
        }
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   285
        List<IOException> errors = ucp.closeLoaders();
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   286
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   287
        // now close any remaining streams.
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   288
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   289
        synchronized (closeables) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   290
            Set<Closeable> keys = closeables.keySet();
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   291
            for (Closeable c : keys) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   292
                try {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   293
                    c.close();
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   294
                } catch (IOException ioex) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   295
                    errors.add(ioex);
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   296
                }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   297
            }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   298
            closeables.clear();
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   299
        }
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   300
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   301
        if (errors.isEmpty()) {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   302
            return;
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   303
        }
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   304
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   305
        IOException firstex = errors.remove(0);
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   306
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   307
        // Suppress any remaining exceptions
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   308
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   309
        for (IOException error: errors) {
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   310
            firstex.addSuppressed(error);
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   311
        }
7983
fb83b663cadc 6829919: URLClassLoader.close() doesn't close resource file if getResourceAsStream(...) was called before
michaelm
parents: 5506
diff changeset
   312
        throw firstex;
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   313
    }
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   314
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Appends the specified URL to the list of URLs to search for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <p>
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   319
     * If the URL specified is {@code null} or is already in the
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   320
     * list of URLs, or if this loader is closed, then invoking this
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   321
     * method has no effect.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param url the URL to be added to the search path of URLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    protected void addURL(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        ucp.addURL(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Returns the search path of URLs for loading classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * This includes the original list of URLs specified to the constructor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * along with any URLs subsequently appended by the addURL() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @return the search path of URLs for loading classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public URL[] getURLs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return ucp.getURLs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Finds and loads the class with the specified name from the URL search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * path. Any URLs referring to JAR files are loaded and opened as needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * until the class is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @param name the name of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @return the resulting class
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   346
     * @exception ClassNotFoundException if the class could not be found,
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   347
     *            or if the loader is closed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    protected Class<?> findClass(final String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        try {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   353
            return AccessController.doPrivileged(
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 9035
diff changeset
   354
                new PrivilegedExceptionAction<Class<?>>() {
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 9035
diff changeset
   355
                    public Class<?> run() throws ClassNotFoundException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                        String path = name.replace('.', '/').concat(".class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        Resource res = ucp.getResource(path, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                return defineClass(name, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                throw new ClassNotFoundException(name, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                            throw new ClassNotFoundException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                }, acc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        } catch (java.security.PrivilegedActionException pae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            throw (ClassNotFoundException) pae.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /*
3228
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   375
     * Retrieve the package using the specified package name.
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   376
     * If non-null, verify the package using the specified code
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   377
     * source and manifest.
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   378
     */
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   379
    private Package getAndVerifyPackage(String pkgname,
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   380
                                        Manifest man, URL url) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   381
        Package pkg = getPackage(pkgname);
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   382
        if (pkg != null) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   383
            // Package found, so check package sealing.
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   384
            if (pkg.isSealed()) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   385
                // Verify that code source URL is the same.
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   386
                if (!pkg.isSealed(url)) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   387
                    throw new SecurityException(
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   388
                        "sealing violation: package " + pkgname + " is sealed");
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   389
                }
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   390
            } else {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   391
                // Make sure we are not attempting to seal the package
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   392
                // at this code source URL.
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   393
                if ((man != null) && isSealed(pkgname, man)) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   394
                    throw new SecurityException(
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   395
                        "sealing violation: can't seal package " + pkgname +
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   396
                        ": already loaded");
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   397
                }
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   398
            }
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   399
        }
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   400
        return pkg;
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   401
    }
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   402
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   403
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Defines a Class using the class bytes obtained from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Resource. The resulting Class must be resolved before it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 9035
diff changeset
   408
    private Class<?> defineClass(String name, Resource res) throws IOException {
3849
34469964aa98 6878481: Add performance counters in the JDK
mchung
parents: 3228
diff changeset
   409
        long t0 = System.nanoTime();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        int i = name.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        URL url = res.getCodeSourceURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (i != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            String pkgname = name.substring(0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            // Check if package already loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            Manifest man = res.getManifest();
3228
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   416
            if (getAndVerifyPackage(pkgname, man, url) == null) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   417
                try {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   418
                    if (man != null) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   419
                        definePackage(pkgname, man, url);
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   420
                    } else {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   421
                        definePackage(pkgname, null, null, null, null, null, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    }
3228
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   423
                } catch (IllegalArgumentException iae) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   424
                    // parallel-capable class loaders: re-verify in case of a
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   425
                    // race condition
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   426
                    if (getAndVerifyPackage(pkgname, man, url) == null) {
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   427
                        // Should never happen
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   428
                        throw new AssertionError("Cannot find package " +
d7c00dbea781 6832540: IllegalArgumentException in ClassLoader.definePackage when classes are loaded in parallel
valeriep
parents: 2448
diff changeset
   429
                                                 pkgname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // Now read the class bytes and define the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        java.nio.ByteBuffer bb = res.getByteBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (bb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            // Use (direct) ByteBuffer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            CodeSigner[] signers = res.getCodeSigners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            CodeSource cs = new CodeSource(url, signers);
3849
34469964aa98 6878481: Add performance counters in the JDK
mchung
parents: 3228
diff changeset
   440
            sun.misc.PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return defineClass(name, bb, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            byte[] b = res.getBytes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            // must read certificates AFTER reading bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            CodeSigner[] signers = res.getCodeSigners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            CodeSource cs = new CodeSource(url, signers);
3849
34469964aa98 6878481: Add performance counters in the JDK
mchung
parents: 3228
diff changeset
   447
            sun.misc.PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            return defineClass(name, b, 0, b.length, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Defines a new package by name in this ClassLoader. The attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * contained in the specified Manifest will be used to obtain package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * version and sealing information. For sealed packages, the additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * URL specifies the code source URL from which the package was loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param name  the package name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param man   the Manifest containing package version and sealing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *              information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @param url   the code source url for the package, or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @exception   IllegalArgumentException if the package name duplicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *              an existing package either in this class loader or one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *              of its ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @return the newly defined Package object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    protected Package definePackage(String name, Manifest man, URL url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        String path = name.replace('.', '/').concat("/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        String specTitle = null, specVersion = null, specVendor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        String implTitle = null, implVersion = null, implVendor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        String sealed = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        URL sealBase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        Attributes attr = man.getAttributes(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            specTitle   = attr.getValue(Name.SPECIFICATION_TITLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            specVendor  = attr.getValue(Name.SPECIFICATION_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            implTitle   = attr.getValue(Name.IMPLEMENTATION_TITLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            implVendor  = attr.getValue(Name.IMPLEMENTATION_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            sealed      = attr.getValue(Name.SEALED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        attr = man.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            if (specTitle == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            if (specVersion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            if (specVendor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            if (implTitle == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if (implVersion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            if (implVendor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            if (sealed == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                sealed = attr.getValue(Name.SEALED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if ("true".equalsIgnoreCase(sealed)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            sealBase = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        return definePackage(name, specTitle, specVersion, specVendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                             implTitle, implVersion, implVendor, sealBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Returns true if the specified package name is sealed according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * given manifest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    private boolean isSealed(String name, Manifest man) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        String path = name.replace('.', '/').concat("/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        Attributes attr = man.getAttributes(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        String sealed = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            sealed = attr.getValue(Name.SEALED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        if (sealed == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if ((attr = man.getMainAttributes()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                sealed = attr.getValue(Name.SEALED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        return "true".equalsIgnoreCase(sealed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * Finds the resource with the specified name on the URL search path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @param name the name of the resource
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   540
     * @return a {@code URL} for the resource, or {@code null}
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   541
     * if the resource could not be found, or if the loader is closed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public URL findResource(final String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         * The same restriction to finding classes applies to resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   547
        URL url = AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   548
            new PrivilegedAction<URL>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   549
                public URL run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    return ucp.findResource(name, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }, acc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return url != null ? ucp.checkURL(url) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * Returns an Enumeration of URLs representing all of the resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * on the URL search path having the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @param name the resource name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @exception IOException if an I/O exception occurs
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   563
     * @return an {@code Enumeration} of {@code URL}s
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   564
     *         If the loader is closed, the Enumeration will be empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    public Enumeration<URL> findResources(final String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   569
        final Enumeration<URL> e = ucp.findResources(name, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return new Enumeration<URL>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            private URL url = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            private boolean next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                if (url != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                do {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   579
                    URL u = AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   580
                        new PrivilegedAction<URL>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   581
                            public URL run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                if (!e.hasMoreElements())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                return e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                        }, acc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    if (u == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    url = ucp.checkURL(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                } while (url == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                return url != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            public URL nextElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                if (!next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                URL u = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                url = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                return u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                return next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * Returns the permissions for the given codesource object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * The implementation of this method first calls super.getPermissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * and then adds permissions based on the URL of the codesource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * If the protocol of this URL is "jar", then the permission granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * is based on the permission that is required by the URL of the Jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * If the protocol is "file" and there is an authority component, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * permission to connect to and accept connections from that authority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * may be granted. If the protocol is "file"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * and the path specifies a file, then permission to read that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * file is granted. If protocol is "file" and the path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * a directory, permission is granted to read all files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * and (recursively) all files and subdirectories contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * that directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * If the protocol is not "file", then permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * to connect to and accept connections from the URL's host is granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @param codesource the codesource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @return the permissions granted to the codesource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    protected PermissionCollection getPermissions(CodeSource codesource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        PermissionCollection perms = super.getPermissions(codesource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        URL url = codesource.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        Permission p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        URLConnection urlConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            urlConnection = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            p = urlConnection.getPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        } catch (java.io.IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            p = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            urlConnection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        if (p instanceof FilePermission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            // if the permission has a separator char on the end,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            // it means the codebase is a directory, and we need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            // to add an additional permission to read recursively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            String path = p.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            if (path.endsWith(File.separator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                path += "-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                p = new FilePermission(path, SecurityConstants.FILE_READ_ACTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        } else if ((p == null) && (url.getProtocol().equals("file"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            String path = url.getFile().replace('/', File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            path = ParseUtil.decode(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            if (path.endsWith(File.separator))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                path += "-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            p =  new FilePermission(path, SecurityConstants.FILE_READ_ACTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
             * Not loading from a 'file:' URL so we want to give the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
             * permission to connect to and accept from the remote host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
             * after we've made sure the host is the correct one and is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            URL locUrl = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            if (urlConnection instanceof JarURLConnection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                locUrl = ((JarURLConnection)urlConnection).getJarFileURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            String host = locUrl.getHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            if (host != null && (host.length() > 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                p = new SocketPermission(host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                                         SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        // make sure the person that created this class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        // would have this permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            final SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                final Permission fp = p;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   687
                AccessController.doPrivileged(new PrivilegedAction<Void>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   688
                    public Void run() throws SecurityException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        sm.checkPermission(fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                }, acc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            perms.add(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        return perms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * Creates a new instance of URLClassLoader for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * URLs and parent class loader. If a security manager is
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   702
     * installed, the {@code loadClass} method of the URLClassLoader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * returned by this method will invoke the
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   704
     * {@code SecurityManager.checkPackageAccess} method before
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * loading the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @param urls the URLs to search for classes and resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @param parent the parent class loader for delegation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @return the resulting class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    public static URLClassLoader newInstance(final URL[] urls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                                             final ClassLoader parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        // Save the caller's context
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   714
        final AccessControlContext acc = AccessController.getContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        // Need a privileged block to create the class loader
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   716
        URLClassLoader ucl = AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   717
            new PrivilegedAction<URLClassLoader>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   718
                public URLClassLoader run() {
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   719
                    return new FactoryURLClassLoader(urls, parent, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        return ucl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Creates a new instance of URLClassLoader for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * URLs and default parent class loader. If a security manager is
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   728
     * installed, the {@code loadClass} method of the URLClassLoader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * returned by this method will invoke the
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 15682
diff changeset
   730
     * {@code SecurityManager.checkPackageAccess} before
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * loading the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * @param urls the URLs to search for classes and resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @return the resulting class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    public static URLClassLoader newInstance(final URL[] urls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        // Save the caller's context
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   738
        final AccessControlContext acc = AccessController.getContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        // Need a privileged block to create the class loader
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   740
        URLClassLoader ucl = AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   741
            new PrivilegedAction<URLClassLoader>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   742
                public URLClassLoader run() {
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   743
                    return new FactoryURLClassLoader(urls, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        return ucl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        sun.misc.SharedSecrets.setJavaNetAccess (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            new sun.misc.JavaNetAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                public URLClassPath getURLClassPath (URLClassLoader u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                    return u.ucp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        );
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   757
        ClassLoader.registerAsParallelCapable();
2
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
final class FactoryURLClassLoader extends URLClassLoader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   763
    static {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   764
        ClassLoader.registerAsParallelCapable();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   767
    FactoryURLClassLoader(URL[] urls, ClassLoader parent,
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   768
                          AccessControlContext acc) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   769
        super(urls, parent, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   772
    FactoryURLClassLoader(URL[] urls, AccessControlContext acc) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   773
        super(urls, acc);
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   774
    }
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 1940
diff changeset
   775
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 9035
diff changeset
   776
    public final Class<?> loadClass(String name, boolean resolve)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        // First check if we have permission to access the package. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        // should go away once we've added support for exported packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            int i = name.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            if (i != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                sm.checkPackageAccess(name.substring(0, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        return super.loadClass(name, resolve);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
}