jdk/test/java/net/URLClassLoader/B6827999.java
author dsamersoff
Sun, 03 Feb 2013 22:28:08 +0400
changeset 15460 ac08a4bdd0f6
parent 5506 202f599c92aa
permissions -rw-r--r--
8002048: Protocol to discovery of manageable Java processes on a network Summary: Introduce a protocol to discover manageble Java instances across a network subnet, JDP Reviewed-by: sla, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3073
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3073
diff changeset
     2
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
3073
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
     4
 *
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
     8
 *
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    13
 * accompanied this code).
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    14
 *
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3073
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3073
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3073
diff changeset
    21
 * questions.
3073
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    22
 */
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    23
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    24
/*
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    25
 * @test
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    26
 * @bug 6827999
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    27
 * @run main/othervm B6827999
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    28
 * @summary Fix for 6827999
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    29
 */
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    30
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    31
import java.net.*;
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    32
import java.io.*;
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    33
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    34
/**
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    35
 */
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    36
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    37
public class B6827999
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    38
{
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    40
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    41
        URL[] urls = new URL[] {new URL("http://foobar.jar") };
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    42
        MyURLClassLoader ucl = new MyURLClassLoader(urls);
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    43
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    44
        ucl.addURL(new URL("http://foo/bar.jar"));
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    45
        urls = ucl.getURLs();
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    46
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    47
        if (urls.length != 2)
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    48
            throw new RuntimeException("Failed:(1)");
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    49
        ucl.close();
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    50
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    51
        ucl.addURL(new URL("http://foo.bar/bar.jar"));
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    52
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    53
        if (ucl.getURLs().length != 2) {
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    54
            throw new RuntimeException("Failed:(2)");
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    55
        }
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    56
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    57
    }
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    58
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    59
    static class MyURLClassLoader extends URLClassLoader {
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    60
        public MyURLClassLoader(URL[] urls) {
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    61
            super(urls);
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    62
        }
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    63
        public void addURL(URL url) {
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    64
            super.addURL(url);
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    65
        }
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    66
    }
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    67
5e93bd389012 6827999: 6827999: URLClassLoader.addURL(URL) adds URLs to closed class loader
michaelm
parents:
diff changeset
    68
}