Path: blob/master/test/jdk/java/net/URLClassLoader/AddURLTest.java
41149 views
/*1* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6460701 643165126* @run main/othervm AddURLTest27* @summary Fixes for 6460701 & 6431651.28*/2930import java.net.*;31import java.io.*;3233/**34* 6460701 : URLClassLoader:addURL RI behavior inconsistent with a spec in case duplicate URLs35* 6431651 : No description for addURL(URL url) method of URLClassLoader class in case null url36*/3738public class AddURLTest39{40public static void main(String[] args) throws Exception {4142URL[] urls = new URL[] {new URL("http://foobar.jar") };43MyURLClassLoader ucl = new MyURLClassLoader(urls);4445ucl.addURL(null);46ucl.addURL(new URL("http://foobar.jar"));47ucl.addURL(null);48ucl.addURL(new URL("http://foobar.jar"));49ucl.addURL(null);50ucl.addURL(new URL("http://foobar.jar"));5152urls = ucl.getURLs();5354if (urls.length != 1)55throw new RuntimeException(56"Failed: There should only be 1 url in the list of search URLs");5758URL url;59for (int i=0; i<urls.length; i++) {60url = urls[i];61if (url == null || !url.equals(new URL("http://foobar.jar")))62throw new RuntimeException(63"Failed: The url should not be null and should be http://foobar.jar");6465}66}6768static class MyURLClassLoader extends URLClassLoader {69public MyURLClassLoader(URL[] urls) {70super(urls);71}72public void addURL(URL url) {73super.addURL(url);74}75}7677}787980