src/java.base/share/classes/jdk/internal/loader/URLClassPath.java
author weijun
Wed, 08 Aug 2018 08:05:43 +0800
changeset 52171 0da586f1ed05
parent 52164 27135de165ac
child 52172 f54dcfc5a5f8
permissions -rw-r--r--
8208754: The fix for JDK-8194534 needs updates Reviewed-by: alanb, igerasim, rhalade, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52164
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3436
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: 3436
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: 3436
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3436
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3436
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
36674
7ab530dd6f10 8149122: Move sun.misc.URLClassPath and Resouce to an internal package
chegar
parents: 36670
diff changeset
    26
package jdk.internal.loader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    28
import java.io.Closeable;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    29
import java.io.File;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    30
import java.io.FileInputStream;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    31
import java.io.FileNotFoundException;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    32
import java.io.IOException;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    33
import java.io.InputStream;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    34
import java.net.HttpURLConnection;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    35
import java.net.JarURLConnection;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    36
import java.net.MalformedURLException;
52164
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
    37
import java.net.URI;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    38
import java.net.URL;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    39
import java.net.URLConnection;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    40
import java.net.URLStreamHandler;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    41
import java.net.URLStreamHandlerFactory;
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
    42
import java.security.AccessControlContext;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    43
import java.security.AccessControlException;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    44
import java.security.AccessController;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    45
import java.security.CodeSigner;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    46
import java.security.Permission;
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
    47
import java.security.PrivilegedActionException;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    48
import java.security.PrivilegedExceptionAction;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    49
import java.security.cert.Certificate;
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
    50
import java.util.ArrayDeque;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    51
import java.util.ArrayList;
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
    52
import java.util.Arrays;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    53
import java.util.Collections;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    54
import java.util.Enumeration;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    55
import java.util.HashMap;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    56
import java.util.HashSet;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    57
import java.util.LinkedList;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    58
import java.util.List;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    59
import java.util.NoSuchElementException;
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 36745
diff changeset
    60
import java.util.Properties;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    61
import java.util.Set;
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    62
import java.util.StringTokenizer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.util.jar.JarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.util.zip.ZipEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.util.jar.JarEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.util.jar.Manifest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import java.util.jar.Attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import java.util.jar.Attributes.Name;
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 36000
diff changeset
    69
import java.util.zip.ZipFile;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    70
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
    71
import jdk.internal.misc.JavaNetURLAccess;
32834
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 29986
diff changeset
    72
import jdk.internal.misc.JavaUtilZipFileAccess;
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 29986
diff changeset
    73
import jdk.internal.misc.SharedSecrets;
36745
51effd3e92d0 8152190: Move sun.misc.JarIndex and InvalidJarIndexException to an internal package
chegar
parents: 36674
diff changeset
    74
import jdk.internal.util.jar.InvalidJarIndexError;
51effd3e92d0 8152190: Move sun.misc.JarIndex and InvalidJarIndexException to an internal package
chegar
parents: 36674
diff changeset
    75
import jdk.internal.util.jar.JarIndex;
3436
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
    76
import sun.net.util.URLUtil;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    77
import sun.net.www.ParseUtil;
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 36745
diff changeset
    78
import sun.security.action.GetPropertyAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * This class is used to maintain a search path of URLs for loading classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * and resources from both JAR files and directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @author  David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
public class URLClassPath {
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    87
    private static final String USER_AGENT_JAVA_VERSION = "UA-Java-Version";
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    88
    private static final String JAVA_VERSION;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final boolean DEBUG;
18223
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
    90
    private static final boolean DISABLE_JAR_CHECKING;
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
    91
    private static final boolean DISABLE_ACC_CHECKING;
52164
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
    92
    private static final boolean DISABLE_CP_URL_CHECK;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
    93
    private static final boolean DEBUG_CP_URL_CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    static {
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
    96
        Properties props = GetPropertyAction.privilegedGetProperties();
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 36745
diff changeset
    97
        JAVA_VERSION = props.getProperty("java.version");
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 36745
diff changeset
    98
        DEBUG = (props.getProperty("sun.misc.URLClassPath.debug") != null);
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 36745
diff changeset
    99
        String p = props.getProperty("sun.misc.URLClassPath.disableJarChecking");
18223
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   100
        DISABLE_JAR_CHECKING = p != null ? p.equals("true") || p.equals("") : false;
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   101
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   102
        p = props.getProperty("jdk.net.URLClassPath.disableRestrictedPermissions");
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   103
        DISABLE_ACC_CHECKING = p != null ? p.equals("true") || p.equals("") : false;
52164
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
   104
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
   105
        // This property will be removed in a later release
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
   106
        p = props.getProperty("jdk.net.URLClassPath.disableClassPathURLCheck");
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
   107
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
   108
        DISABLE_CP_URL_CHECK = p != null ? p.equals("true") || p.isEmpty() : false;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
   109
        DEBUG_CP_URL_CHECK = "debug".equals(p);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /* The original search path of URLs. */
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   113
    private final ArrayList<URL> path;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   115
    /* The deque of unopened URLs */
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   116
    private final ArrayDeque<URL> unopenedUrls;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /* The resulting search path of Loaders */
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   119
    private final ArrayList<Loader> loaders = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /* Map of each URL opened to its corresponding Loader */
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   122
    private final HashMap<String, Loader> lmap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /* The jar protocol handler to use when creating new URLs */
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   125
    private final URLStreamHandler jarHandler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   127
    /* Whether this URLClassLoader has been closed yet */
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   128
    private boolean closed = false;
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   129
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   130
    /* The context to be used when loading classes and resources.  If non-null
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   131
     * this is the context that was captured during the creation of the
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   132
     * URLClassLoader. null implies no additional security restrictions. */
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   133
    private final AccessControlContext acc;
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   134
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Creates a new URLClassPath for the given URLs. The URLs will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * searched in the order specified for classes and resources. A URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * ending with a '/' is assumed to refer to a directory. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the URL is assumed to refer to a JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param urls the directory and JAR file URLs to search for classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *        and resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param factory the URLStreamHandlerFactory to use when creating new URLs
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   144
     * @param acc the context to be used when loading classes and resources, may
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   145
     *            be null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   147
    public URLClassPath(URL[] urls,
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   148
                        URLStreamHandlerFactory factory,
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   149
                        AccessControlContext acc) {
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   150
        ArrayList<URL> path = new ArrayList<>(urls.length);
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   151
        ArrayDeque<URL> unopenedUrls = new ArrayDeque<>(urls.length);
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   152
        for (URL url : urls) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   153
            path.add(url);
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   154
            unopenedUrls.add(url);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   156
        this.path = path;
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   157
        this.unopenedUrls = unopenedUrls;
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   158
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (factory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            jarHandler = factory.createURLStreamHandler("jar");
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   161
        } else {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   162
            jarHandler = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   164
        if (DISABLE_ACC_CHECKING)
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   165
            this.acc = null;
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   166
        else
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   167
            this.acc = acc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   170
    public URLClassPath(URL[] urls, AccessControlContext acc) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   171
        this(urls, null, acc);
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   172
    }
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   173
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   174
    /**
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   175
     * Constructs a URLClassPath from a class path string.
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   176
     *
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   177
     * @param cp the class path string
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   178
     * @param skipEmptyElements indicates if empty elements are ignored or
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   179
     *        treated as the current working directory
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   180
     *
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   181
     * @apiNote Used to create the application class path.
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   182
     */
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   183
    URLClassPath(String cp, boolean skipEmptyElements) {
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   184
        ArrayList<URL> path = new ArrayList<>();
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   185
        if (cp != null) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   186
            // map each element of class path to a file URL
48998
43bf8cca0ecc 8198485: Simplify a URLClassPath constructor
martin
parents: 48997
diff changeset
   187
            int off = 0, next;
43bf8cca0ecc 8198485: Simplify a URLClassPath constructor
martin
parents: 48997
diff changeset
   188
            do {
43bf8cca0ecc 8198485: Simplify a URLClassPath constructor
martin
parents: 48997
diff changeset
   189
                next = cp.indexOf(File.pathSeparator, off);
43bf8cca0ecc 8198485: Simplify a URLClassPath constructor
martin
parents: 48997
diff changeset
   190
                String element = (next == -1)
43bf8cca0ecc 8198485: Simplify a URLClassPath constructor
martin
parents: 48997
diff changeset
   191
                    ? cp.substring(off)
43bf8cca0ecc 8198485: Simplify a URLClassPath constructor
martin
parents: 48997
diff changeset
   192
                    : cp.substring(off, next);
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   193
                if (element.length() > 0 || !skipEmptyElements) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   194
                    URL url = toFileURL(element);
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   195
                    if (url != null) path.add(url);
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   196
                }
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   197
                off = next + 1;
48998
43bf8cca0ecc 8198485: Simplify a URLClassPath constructor
martin
parents: 48997
diff changeset
   198
            } while (next != -1);
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   199
        }
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   200
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   201
        // can't use ArrayDeque#addAll or new ArrayDeque(Collection);
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   202
        // it's too early in the bootstrap to trigger use of lambdas
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   203
        int size = path.size();
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   204
        ArrayDeque<URL> unopenedUrls = new ArrayDeque<>(size);
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   205
        for (int i = 0; i < size; i++)
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   206
            unopenedUrls.add(path.get(i));
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   207
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   208
        this.unopenedUrls = unopenedUrls;
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   209
        this.path = path;
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   210
        this.jarHandler = null;
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   211
        this.acc = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   214
    public synchronized List<IOException> closeLoaders() {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   215
        if (closed) {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   216
            return Collections.emptyList();
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   217
        }
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27565
diff changeset
   218
        List<IOException> result = new LinkedList<>();
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   219
        for (Loader loader : loaders) {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   220
            try {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   221
                loader.close();
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   222
            } catch (IOException e) {
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   223
                result.add(e);
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   224
            }
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   225
        }
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   226
        closed = true;
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   227
        return result;
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   228
    }
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   229
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Appends the specified URL to the search path of directory and JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * file URLs from which to load classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * If the URL specified is null or is already in the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * URLs, then invoking this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
3073
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents: 1940
diff changeset
   237
    public synchronized void addURL(URL url) {
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   238
        if (closed || url == null)
3073
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents: 1940
diff changeset
   239
            return;
48996
1c28a76198da 8198482: The URLClassPath field "urls" should be renamed to "unopenedUrls"
martin
parents: 48995
diff changeset
   240
        synchronized (unopenedUrls) {
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   241
            if (! path.contains(url)) {
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   242
                unopenedUrls.addLast(url);
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   243
                path.add(url);
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   244
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   249
     * Appends the specified file path as a file URL to the search path.
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   250
     */
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   251
    public void addFile(String s) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   252
        URL url = toFileURL(s);
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   253
        if (url != null) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   254
            addURL(url);
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   255
        }
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   256
    }
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   257
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   258
    /**
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   259
     * Returns a file URL for the given file path.
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   260
     */
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   261
    private static URL toFileURL(String s) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   262
        try {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   263
            File f = new File(s).getCanonicalFile();
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   264
            return ParseUtil.fileToEncodedURL(f);
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   265
        } catch (IOException e) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   266
            return null;
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   267
        }
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   268
    }
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   269
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 43800
diff changeset
   270
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Returns the original search path of URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public URL[] getURLs() {
48996
1c28a76198da 8198482: The URLClassPath field "urls" should be renamed to "unopenedUrls"
martin
parents: 48995
diff changeset
   274
        synchronized (unopenedUrls) {
1c28a76198da 8198482: The URLClassPath field "urls" should be renamed to "unopenedUrls"
martin
parents: 48995
diff changeset
   275
            return path.toArray(new URL[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Finds the resource with the specified name on the URL search path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * or null if not found or security check fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param name      the name of the resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param check     whether to perform a security check
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   285
     * @return a {@code URL} for the resource, or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * if the resource could not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public URL findResource(String name, boolean check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        Loader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        for (int i = 0; (loader = getLoader(i)) != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            URL url = loader.findResource(name, check);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (url != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Finds the first Resource on the URL search path which has the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * name. Returns null if no Resource could be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param name the name of the Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param check     whether to perform a security check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @return the Resource, or null if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public Resource getResource(String name, boolean check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            System.err.println("URLClassPath.getResource(\"" + name + "\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        Loader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        for (int i = 0; (loader = getLoader(i)) != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            Resource res = loader.getResource(name, check);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Finds all resources on the URL search path with the given name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Returns an enumeration of the URL objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @param name the resource name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @return an Enumeration of all the urls having the specified name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   329
    public Enumeration<URL> findResources(final String name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                     final boolean check) {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27565
diff changeset
   331
        return new Enumeration<>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            private int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            private URL url = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            private boolean next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                if (url != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    Loader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    while ((loader = getLoader(index++)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        url = loader.findResource(name, check);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        if (url != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                return next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   354
            public URL nextElement() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                if (!next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                URL u = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                url = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                return u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public Resource getResource(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return getResource(name, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Finds all resources on the URL search path with the given name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Returns an enumeration of the Resource objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param name the resource name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @return an Enumeration of all the resources having the specified name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   376
    public Enumeration<Resource> getResources(final String name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                    final boolean check) {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27565
diff changeset
   378
        return new Enumeration<>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            private int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            private Resource res = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            private boolean next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    Loader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    while ((loader = getLoader(index++)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                        res = loader.getResource(name, check);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                return next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   401
            public Resource nextElement() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                if (!next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                Resource r = res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                res = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   412
    public Enumeration<Resource> getResources(final String name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return getResources(name, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Returns the Loader at the specified position in the URL search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * path. The URLs are opened and expanded as needed. Returns null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * if the specified index is out of range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   421
    private synchronized Loader getLoader(int index) {
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   422
        if (closed) {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   423
            return null;
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   424
        }
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   425
        // Expand URL search path until the request can be satisfied
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   426
        // or unopenedUrls is exhausted.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        while (loaders.size() < index + 1) {
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   428
            final URL url;
48996
1c28a76198da 8198482: The URLClassPath field "urls" should be renamed to "unopenedUrls"
martin
parents: 48995
diff changeset
   429
            synchronized (unopenedUrls) {
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   430
                url = unopenedUrls.pollFirst();
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   431
                if (url == null)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            // Skip this URL if it already has a Loader. (Loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            // may be null in the case where URL has not been opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            // but is referenced by a JAR index.)
3436
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   437
            String urlNoFragString = URLUtil.urlNoFragString(url);
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   438
            if (lmap.containsKey(urlNoFragString)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            // Otherwise, create a new Loader for the URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            Loader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                loader = getLoader(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                // If the loader defines a local class path then add the
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   446
                // URLs as the next URLs to be opened.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                URL[] urls = loader.getClassPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                if (urls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    push(urls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                // Silently ignore for now...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                continue;
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   454
            } catch (SecurityException se) {
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   455
                // Always silently ignore. The context, if there is one, that
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   456
                // this URLClassPath was given during construction will never
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   457
                // have permission to access the URL.
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   458
                if (DEBUG) {
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   459
                    System.err.println("Failed to access " + url + ", " + se );
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   460
                }
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   461
                continue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            // Finally, add the Loader to the search path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            loaders.add(loader);
3436
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   465
            lmap.put(urlNoFragString, loader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   467
        return loaders.get(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Returns the Loader for the specified base URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    private Loader getLoader(final URL url) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        try {
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   475
            return AccessController.doPrivileged(
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   476
                    new PrivilegedExceptionAction<>() {
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   477
                        public Loader run() throws IOException {
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   478
                            String protocol = url.getProtocol();  // lower cased in URL
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   479
                            String file = url.getFile();
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   480
                            if (file != null && file.endsWith("/")) {
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   481
                                if ("file".equals(protocol)) {
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   482
                                    return new FileLoader(url);
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   483
                                } else if ("jar".equals(protocol) &&
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   484
                                        isDefaultJarHandler(url) &&
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   485
                                        file.endsWith("!/")) {
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   486
                                    // extract the nested URL
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   487
                                    URL nestedUrl = new URL(file.substring(0, file.length() - 2));
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   488
                                    return new JarLoader(nestedUrl, jarHandler, lmap, acc);
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   489
                                } else {
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   490
                                    return new Loader(url);
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   491
                                }
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   492
                            } else {
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   493
                                return new JarLoader(url, jarHandler, lmap, acc);
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   494
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        }
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   496
                    }, acc);
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   497
        } catch (PrivilegedActionException pae) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            throw (IOException)pae.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   502
    private static final JavaNetURLAccess JNUA
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   503
            = SharedSecrets.getJavaNetURLAccess();
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   504
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   505
    private static boolean isDefaultJarHandler(URL u) {
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   506
        URLStreamHandler h = JNUA.getHandler(u);
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   507
        return h instanceof sun.net.www.protocol.jar.Handler;
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   508
    }
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   509
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /*
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   511
     * Pushes the specified URLs onto the head of unopened URLs.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
48996
1c28a76198da 8198482: The URLClassPath field "urls" should be renamed to "unopenedUrls"
martin
parents: 48995
diff changeset
   513
    private void push(URL[] urls) {
1c28a76198da 8198482: The URLClassPath field "urls" should be renamed to "unopenedUrls"
martin
parents: 48995
diff changeset
   514
        synchronized (unopenedUrls) {
1c28a76198da 8198482: The URLClassPath field "urls" should be renamed to "unopenedUrls"
martin
parents: 48995
diff changeset
   515
            for (int i = urls.length - 1; i >= 0; --i) {
48997
12c61ec06d2a 8198484: URLClassPath should use an ArrayDeque instead of a Stack
martin
parents: 48996
diff changeset
   516
                unopenedUrls.addFirst(urls[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /*
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   522
     * Checks whether the resource URL should be returned.
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   523
     * Returns null on security check failure.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Called by java.net.URLClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36251
diff changeset
   526
    public static URL checkURL(URL url) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36251
diff changeset
   527
        if (url != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36251
diff changeset
   528
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36251
diff changeset
   529
                check(url);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36251
diff changeset
   530
            } catch (Exception e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36251
diff changeset
   531
                return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36251
diff changeset
   532
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /*
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   538
     * Checks whether the resource URL should be returned.
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   539
     * Throws exception on failure.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Called internally within this file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36251
diff changeset
   542
    public static void check(URL url) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            URLConnection urlConnection = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            Permission perm = urlConnection.getPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            if (perm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    security.checkPermission(perm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    // fallback to checkRead/checkConnect for pre 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    // security managers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    if ((perm instanceof java.io.FilePermission) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        perm.getActions().indexOf("read") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        security.checkRead(perm.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    } else if ((perm instanceof
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        java.net.SocketPermission) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                        perm.getActions().indexOf("connect") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                        URL locUrl = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        if (urlConnection instanceof JarURLConnection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                            locUrl = ((JarURLConnection)urlConnection).getJarFileURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                        security.checkConnect(locUrl.getHost(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                              locUrl.getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                        throw se;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    /**
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   574
     * Nested class used to represent a loader of resources and classes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * from a base URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   577
    private static class Loader implements Closeable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        private final URL base;
7980
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   579
        private JarFile jarfile; // if this points to a jar file
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
         * Creates a new Loader for the specified URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        Loader(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            base = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         * Returns the base URL for this Loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        URL getBaseURL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            return base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        URL findResource(final String name, boolean check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                url = new URL(base, ParseUtil.encodePath(name, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                throw new IllegalArgumentException("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                if (check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    URLClassPath.check(url);
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
                 * For a HTTP connection we use the HEAD method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                 * check if the resource exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                URLConnection uc = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                if (uc instanceof HttpURLConnection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    HttpURLConnection hconn = (HttpURLConnection)uc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    hconn.setRequestMethod("HEAD");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    if (hconn.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    // our best guess for the other cases
15305
45a0eb6ab4f7 7183373: URLClassloader.close() does not close JAR files whose resources have been loaded via getResource()
dingxmin
parents: 11131
diff changeset
   621
                    uc.setUseCaches(false);
45a0eb6ab4f7 7183373: URLClassloader.close() does not close JAR files whose resources have been loaded via getResource()
dingxmin
parents: 11131
diff changeset
   622
                    InputStream is = uc.getInputStream();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        Resource getResource(final String name, boolean check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            final URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                url = new URL(base, ParseUtil.encodePath(name, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                throw new IllegalArgumentException("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            final URLConnection uc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                if (check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    URLClassPath.check(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                uc = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                InputStream in = uc.getInputStream();
7980
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   645
                if (uc instanceof JarURLConnection) {
9823
2bc6b0d4490e 7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents: 9035
diff changeset
   646
                    /* Need to remember the jar file so it can be closed
7980
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   647
                     * in a hurry.
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   648
                     */
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   649
                    JarURLConnection juc = (JarURLConnection)uc;
18223
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   650
                    jarfile = JarLoader.checkJar(juc.getJarFile());
7980
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   651
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            return new Resource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                public String getName() { return name; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                public URL getURL() { return url; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                public URL getCodeSourceURL() { return base; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                public InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    return uc.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                public int getContentLength() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                    return uc.getContentLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
         * Returns the Resource for the specified name, or null if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
         * found or the caller does not have the permission to get the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
         * resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        Resource getResource(final String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            return getResource(name, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        /*
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   678
         * Closes this loader and release all resources.
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   679
         * Method overridden in sub-classes.
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   680
         */
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   681
        @Override
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   682
        public void close() throws IOException {
7980
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   683
            if (jarfile != null) {
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   684
                jarfile.close();
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   685
            }
3af394bb6f59 6896088: URLClassLoader.close() apparently not working for JAR URLs on Windows
michaelm
parents: 5506
diff changeset
   686
        }
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   687
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   688
        /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
         * Returns the local class path for this loader, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        URL[] getClassPath() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    /*
47866
39db80b32b69 8191632: Typos in comments due to duplicating words
igerasim
parents: 47216
diff changeset
   697
     * Nested class used to represent a Loader of resources from a JAR URL.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    static class JarLoader extends Loader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        private JarFile jar;
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   701
        private final URL csu;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        private JarIndex index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        private URLStreamHandler handler;
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   704
        private final HashMap<String, Loader> lmap;
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   705
        private final AccessControlContext acc;
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   706
        private boolean closed = false;
32834
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 29986
diff changeset
   707
        private static final JavaUtilZipFileAccess zipAccess =
e1dca5fe4de3 8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents: 29986
diff changeset
   708
                SharedSecrets.getJavaUtilZipFileAccess();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
         * Creates a new JarLoader for the specified URL referring to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
         * a JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
         */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   714
        JarLoader(URL url, URLStreamHandler jarHandler,
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   715
                  HashMap<String, Loader> loaderMap,
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   716
                  AccessControlContext acc)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            super(new URL("jar", "", -1, url + "!/", jarHandler));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            csu = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            handler = jarHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            lmap = loaderMap;
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   723
            this.acc = acc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
36000
86257b272c96 8068686: Remove meta-index support
chegar
parents: 32834
diff changeset
   725
            ensureOpen();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
1940
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   728
        @Override
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   729
        public void close () throws IOException {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   730
            // closing is synchronized at higher level
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   731
            if (!closed) {
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   732
                closed = true;
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   733
                // in case not already open.
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   734
                ensureOpen();
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   735
                jar.close();
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   736
            }
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   737
        }
e81514210873 4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents: 715
diff changeset
   738
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        JarFile getJarFile () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            return jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        private boolean isOptimizable(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            return "file".equals(url.getProtocol());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            if (jar == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                try {
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   750
                    AccessController.doPrivileged(
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   751
                        new PrivilegedExceptionAction<>() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   752
                            public Void run() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                                    System.err.println("Opening " + csu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                                    Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                                jar = getJarFile(csu);
36000
86257b272c96 8068686: Remove meta-index support
chegar
parents: 32834
diff changeset
   759
                                index = JarIndex.getJarIndex(jar);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                                if (index != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                                    String[] jarfiles = index.getJarFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                                // Add all the dependent URLs to the lmap so that loaders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                                // will not be created for them by URLClassPath.getLoader(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                                // if the same URL occurs later on the main class path.  We set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                // Loader to null here to avoid creating a Loader for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                                // URL until we actually need to try to load something from them.
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   767
                                    for (int i = 0; i < jarfiles.length; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                                            URL jarURL = new URL(csu, jarfiles[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                                            // If a non-null loader already exists, leave it alone.
3436
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   771
                                            String urlNoFragString = URLUtil.urlNoFragString(jarURL);
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   772
                                            if (!lmap.containsKey(urlNoFragString)) {
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   773
                                                lmap.put(urlNoFragString, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                                        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                            }
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   782
                        }, acc);
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   783
                } catch (PrivilegedActionException pae) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    throw (IOException)pae.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
18223
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   789
        /* Throws if the given jar file is does not start with the correct LOC */
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   790
        static JarFile checkJar(JarFile jar) throws IOException {
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   791
            if (System.getSecurityManager() != null && !DISABLE_JAR_CHECKING
18273
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   792
                && !zipAccess.startsWithLocHeader(jar)) {
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   793
                IOException x = new IOException("Invalid Jar file");
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   794
                try {
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   795
                    jar.close();
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   796
                } catch (IOException ex) {
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   797
                    x.addSuppressed(ex);
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   798
                }
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   799
                throw x;
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   800
            }
407ff7067681 8012156: tools/javac/file/zip/T6865530.java fails for win32/64 in 7u25 nightly runs
chegar
parents: 18223
diff changeset
   801
18223
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   802
            return jar;
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   803
        }
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   804
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        private JarFile getJarFile(URL url) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            // Optimize case where url refers to a local jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            if (isOptimizable(url)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                FileURLMapper p = new FileURLMapper (url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                if (!p.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    throw new FileNotFoundException(p.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                }
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 36000
diff changeset
   812
                return checkJar(new JarFile(new File(p.getPath()), true, ZipFile.OPEN_READ,
39646
2bf99fe5023b 8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents: 37785
diff changeset
   813
                        JarFile.runtimeVersion()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            }
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 36000
diff changeset
   815
            URLConnection uc = (new URL(getBaseURL(), "#runtime")).openConnection();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            uc.setRequestProperty(USER_AGENT_JAVA_VERSION, JAVA_VERSION);
18223
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   817
            JarFile jarFile = ((JarURLConnection)uc).getJarFile();
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 16023
diff changeset
   818
            return checkJar(jarFile);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
         * Returns the index of this JarLoader if it exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        JarIndex getIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            } catch (IOException e) {
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 9823
diff changeset
   828
                throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
         * Creates the resource and if the check flag is set to true, checks if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
         * is its okay to return the resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        Resource checkResource(final String name, boolean check,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            final JarEntry entry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            final URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            try {
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   842
                String nm;
36251
e909478d3e1d 8151339: Adding fragment to JAR URLs breaks ant
sdrach
parents: 36129
diff changeset
   843
                if (jar.isMultiRelease()) {
47987
85ea7e83af30 8189611: JarFile versioned stream and real name support
sherman
parents: 47866
diff changeset
   844
                    nm = entry.getRealName();
36251
e909478d3e1d 8151339: Adding fragment to JAR URLs breaks ant
sdrach
parents: 36129
diff changeset
   845
                } else {
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   846
                    nm = name;
36251
e909478d3e1d 8151339: Adding fragment to JAR URLs breaks ant
sdrach
parents: 36129
diff changeset
   847
                }
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
   848
                url = new URL(getBaseURL(), ParseUtil.encodePath(nm, false));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                if (check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                    URLClassPath.check(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                // throw new IllegalArgumentException("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            } catch (AccessControlException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            return new Resource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                public String getName() { return name; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                public URL getURL() { return url; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                public URL getCodeSourceURL() { return csu; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                public InputStream getInputStream() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    { return jar.getInputStream(entry); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                public int getContentLength()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                    { return (int)entry.getSize(); }
52171
0da586f1ed05 8208754: The fix for JDK-8194534 needs updates
weijun
parents: 52164
diff changeset
   869
                public Manifest getManifest() throws IOException {
0da586f1ed05 8208754: The fix for JDK-8194534 needs updates
weijun
parents: 52164
diff changeset
   870
                    SharedSecrets.javaUtilJarAccess().ensureInitialization(jar);
0da586f1ed05 8208754: The fix for JDK-8194534 needs updates
weijun
parents: 52164
diff changeset
   871
                    return jar.getManifest();
0da586f1ed05 8208754: The fix for JDK-8194534 needs updates
weijun
parents: 52164
diff changeset
   872
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                public Certificate[] getCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    { return entry.getCertificates(); };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                public CodeSigner[] getCodeSigners()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                    { return entry.getCodeSigners(); };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        /*
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   882
         * Returns true iff at least one resource in the jar file has the same
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * package name as that of the specified resource name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        boolean validIndex(final String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            String packageName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            int pos;
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   888
            if ((pos = name.lastIndexOf('/')) != -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                packageName = name.substring(0, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            String entryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            ZipEntry entry;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   894
            Enumeration<JarEntry> enum_ = jar.entries();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            while (enum_.hasMoreElements()) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   896
                entry = enum_.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                entryName = entry.getName();
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   898
                if ((pos = entryName.lastIndexOf('/')) != -1)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    entryName = entryName.substring(0, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                if (entryName.equals(packageName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
         * Returns the URL for a resource with the specified name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
         */
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   910
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        URL findResource(final String name, boolean check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            Resource rsc = getResource(name, check);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            if (rsc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                return rsc.getURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
         * Returns the JAR Resource for the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
         */
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
   922
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        Resource getResource(final String name, boolean check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            } catch (IOException e) {
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 9823
diff changeset
   927
                throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            final JarEntry entry = jar.getJarEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            if (entry != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                return checkResource(name, check, entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            if (index == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27565
diff changeset
   936
            HashSet<String> visited = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            return getResource(name, check, visited);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
         * Version of getResource() that tracks the jar files that have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
         * visited by linking through the index files. This helper method uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
         * a HashSet to store the URLs of jar files that have been searched and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
         * uses it to avoid going into an infinite loop, looking for a
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   945
         * non-existent resource.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        Resource getResource(final String name, boolean check,
3436
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   948
                             Set<String> visited) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            Resource res;
11131
27747ee5a62a 7116857: Warnings in javax.security and some sun.misc
weijun
parents: 10355
diff changeset
   950
            String[] jarFiles;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            int count = 0;
11131
27747ee5a62a 7116857: Warnings in javax.security and some sun.misc
weijun
parents: 10355
diff changeset
   952
            LinkedList<String> jarFilesList = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            /* If there no jar files in the index that can potential contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
             * this resource then return immediately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
             */
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   957
            if ((jarFilesList = index.get(name)) == null)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                int size = jarFilesList.size();
11131
27747ee5a62a 7116857: Warnings in javax.security and some sun.misc
weijun
parents: 10355
diff changeset
   962
                jarFiles = jarFilesList.toArray(new String[size]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                /* loop through the mapped jar file list */
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   964
                while (count < size) {
11131
27747ee5a62a 7116857: Warnings in javax.security and some sun.misc
weijun
parents: 10355
diff changeset
   965
                    String jarName = jarFiles[count++];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    JarLoader newLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    final URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    try{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                        url = new URL(csu, jarName);
3436
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   971
                        String urlNoFragString = URLUtil.urlNoFragString(url);
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   972
                        if ((newLoader = (JarLoader)lmap.get(urlNoFragString)) == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                            /* no loader has been set up for this jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                             * before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                             */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   976
                            newLoader = AccessController.doPrivileged(
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 27565
diff changeset
   977
                                new PrivilegedExceptionAction<>() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   978
                                    public JarLoader run() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                                        return new JarLoader(url, handler,
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   980
                                            lmap, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                                    }
43196
2064adad356a 8151934: Resolve class resolution
chegar
parents: 39646
diff changeset
   982
                                }, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                            /* this newly opened jar file has its own index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                             * merge it into the parent's index, taking into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                             * account the relative path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                            JarIndex newIndex = newLoader.getIndex();
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   989
                            if (newIndex != null) {
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 23010
diff changeset
   990
                                int pos = jarName.lastIndexOf('/');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                                newIndex.merge(this.index, (pos == -1 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                                    null : jarName.substring(0, pos + 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                            /* put it in the global hashtable */
3436
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
   996
                            lmap.put(urlNoFragString, newLoader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                        }
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
   998
                    } catch (PrivilegedActionException pae) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                    } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                    /* Note that the addition of the url to the list of visited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                     * jars incorporates a check for presence in the hashmap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                     */
3436
c7d276696c5b 6826780: URLClassPath should use HashMap<String, XXX> instead of HashMap<URL, XXX>
chegar
parents: 3073
diff changeset
  1007
                    boolean visitedURL = !visited.add(URLUtil.urlNoFragString(url));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                    if (!visitedURL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                            newLoader.ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                        } catch (IOException e) {
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 9823
diff changeset
  1012
                            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                        final JarEntry entry = newLoader.jar.getJarEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                        if (entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                            return newLoader.checkResource(name, check, entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                        /* Verify that at least one other resource with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                         * same package name as the lookedup resource is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                         * present in the new jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                        if (!newLoader.validIndex(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                            /* the mapping is wrong */
36745
51effd3e92d0 8152190: Move sun.misc.JarIndex and InvalidJarIndexException to an internal package
chegar
parents: 36674
diff changeset
  1025
                            throw new InvalidJarIndexError("Invalid index");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                    /* If newLoader is the current loader or if it is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                     * loader that has already been searched or if the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                     * loader does not have an index then skip it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                     * and move on to the next loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    if (visitedURL || newLoader == this ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                            newLoader.getIndex() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                    /* Process the index of the new loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                     */
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
  1041
                    if ((res = newLoader.getResource(name, check, visited))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                            != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                // Get the list of jar files again as the list could have grown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                // due to merging of index files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                jarFilesList = index.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            // If the count is unchanged, we are done.
48995
58bec53828ba 8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader
martin
parents: 47987
diff changeset
  1051
            } while (count < jarFilesList.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
         * Returns the JAR file local class path, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
         */
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
  1059
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        URL[] getClassPath() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            if (index != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            ensureOpen();
15682
793a36de151d 8003255: (profiles) Update JAR file specification to support profiles
alanb
parents: 11131
diff changeset
  1066
37785
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
  1067
            // Only get manifest when necessary
daf6dcc73e9d 8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents: 37781
diff changeset
  1068
            if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                Manifest man = jar.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                if (man != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                    Attributes attr = man.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                    if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                        String value = attr.getValue(Name.CLASS_PATH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                            return parseClassPath(csu, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
         * Parses value of the Class-Path manifest attribute and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
         * an array of URLs relative to the specified base URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
         */
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
  1087
        private static URL[] parseClassPath(URL base, String value)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            throws MalformedURLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            StringTokenizer st = new StringTokenizer(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            URL[] urls = new URL[st.countTokens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                String path = st.nextToken();
52164
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1095
                URL url = DISABLE_CP_URL_CHECK ? new URL(base, path) : safeResolve(base, path);
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1096
                if (url != null) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1097
                    urls[i] = url;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1098
                    i++;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1099
                }
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1100
            }
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1101
            if (i == 0) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1102
                urls = null;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1103
            } else if (i != urls.length) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1104
                // Truncate nulls from end of array
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1105
                urls = Arrays.copyOf(urls, i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            return urls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        }
52164
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1109
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1110
        /*
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1111
         * Return a URL for the given path resolved against the base URL, or
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1112
         * null if the resulting URL is invalid.
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1113
         */
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1114
        static URL safeResolve(URL base, String path) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1115
            String child = path.replace(File.separatorChar, '/');
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1116
            try {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1117
                if (!URI.create(child).isAbsolute()) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1118
                    URL url = new URL(base, child);
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1119
                    if (base.getProtocol().equalsIgnoreCase("file")) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1120
                        return url;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1121
                    } else {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1122
                        String bp = base.getPath();
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1123
                        String urlp = url.getPath();
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1124
                        int pos = bp.lastIndexOf('/');
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1125
                        if (pos == -1) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1126
                            pos = bp.length() - 1;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1127
                        }
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1128
                        if (urlp.regionMatches(0, bp, 0, pos + 1)
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1129
                            && urlp.indexOf("..", pos) == -1) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1130
                            return url;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1131
                        }
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1132
                    }
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1133
                }
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1134
            } catch (MalformedURLException | IllegalArgumentException e) {}
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1135
            if (DEBUG_CP_URL_CHECK) {
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1136
                System.err.println("Class-Path entry: \"" + path + "\" ignored in JAR file " + base);
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1137
            }
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1138
            return null;
27135de165ac 8195874: Improve jar specification adherence
bchristi
parents: 48998
diff changeset
  1139
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    /*
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
  1143
     * Nested class used to represent a loader of classes and resources
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * from a file URL that refers to a directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    private static class FileLoader extends Loader {
495
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1147
        /* Canonicalized File */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        private File dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        FileLoader(URL url) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            super(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            if (!"file".equals(url.getProtocol())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                throw new IllegalArgumentException("url");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            String path = url.getFile().replace('/', File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            path = ParseUtil.decode(path);
495
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1157
            dir = (new File(path)).getCanonicalFile();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
         * Returns the URL for a resource with the specified name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
         */
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
  1163
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        URL findResource(final String name, boolean check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            Resource rsc = getResource(name, check);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            if (rsc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                return rsc.getURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
43800
1dc22b50717a 8174151: URLClassLoader no longer uses custom URLStreamHandler for jar URLs
psandoz
parents: 43196
diff changeset
  1172
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        Resource getResource(final String name, boolean check) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            final URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                URL normalizedBase = new URL(getBaseURL(), ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                url = new URL(getBaseURL(), ParseUtil.encodePath(name, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                if (url.getFile().startsWith(normalizedBase.getFile()) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                    // requested resource had ../..'s in path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                if (check)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                    URLClassPath.check(url);
495
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1186
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1187
                final File file;
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1188
                if (name.indexOf("..") != -1) {
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1189
                    file = (new File(dir, name.replace('/', File.separatorChar)))
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1190
                          .getCanonicalFile();
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1191
                    if ( !((file.getPath()).startsWith(dir.getPath())) ) {
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1192
                        /* outside of base dir */
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1193
                        return null;
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1194
                    }
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1195
                } else {
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1196
                    file = new File(dir, name.replace('/', File.separatorChar));
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1197
                }
d612e90c3ebc 6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents: 51
diff changeset
  1198
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                if (file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    return new Resource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                        public String getName() { return name; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                        public URL getURL() { return url; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                        public URL getCodeSourceURL() { return getBaseURL(); };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                        public InputStream getInputStream() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                            { return new FileInputStream(file); };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                        public int getContentLength() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                            { return (int)file.length(); };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
}