Initial load
diff --git a/test/java/net/URLClassLoader/AddURLTest.java b/test/java/net/URLClassLoader/AddURLTest.java
new file mode 100644
index 0000000..d3fff26
--- /dev/null
+++ b/test/java/net/URLClassLoader/AddURLTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6460701 6431651
+ * @run main/othervm AddURLTest
+ * @summary Fixes for 6460701 & 6431651.
+ */
+
+import java.net.*;
+import java.io.*;
+
+/**
+ * 6460701 : URLClassLoader:addURL RI behavior inconsistent with a spec in case duplicate URLs
+ * 6431651 : No description for addURL(URL url) method of URLClassLoader class in case null url
+ */
+
+public class AddURLTest
+{
+ public static void main(String[] args) throws Exception {
+
+ URL[] urls = new URL[] {new URL("http://foobar.jar") };
+ MyURLClassLoader ucl = new MyURLClassLoader(urls);
+
+ ucl.addURL(null);
+ ucl.addURL(new URL("http://foobar.jar"));
+ ucl.addURL(null);
+ ucl.addURL(new URL("http://foobar.jar"));
+ ucl.addURL(null);
+ ucl.addURL(new URL("http://foobar.jar"));
+
+ urls = ucl.getURLs();
+
+ if (urls.length != 1)
+ throw new RuntimeException(
+ "Failed: There should only be 1 url in the list of search URLs");
+
+ URL url;
+ for (int i=0; i<urls.length; i++) {
+ url = urls[i];
+ if (url == null || !url.equals(new URL("http://foobar.jar")))
+ throw new RuntimeException(
+ "Failed: The url should not be null and should be http://foobar.jar");
+
+ }
+ }
+
+ static class MyURLClassLoader extends URLClassLoader {
+ public MyURLClassLoader(URL[] urls) {
+ super(urls);
+ }
+ public void addURL(URL url) {
+ super.addURL(url);
+ }
+ }
+
+}
diff --git a/test/java/net/URLClassLoader/B5077773.java b/test/java/net/URLClassLoader/B5077773.java
new file mode 100644
index 0000000..66e9210
--- /dev/null
+++ b/test/java/net/URLClassLoader/B5077773.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.io.*;
+import java.net.*;
+
+public class B5077773 {
+
+ public static void main(String[] args) throws Exception {
+ URLClassLoader loader = new URLClassLoader (new URL[] {new URL("file:foo.jar")});
+ /* This test will fail if the file below is removed from rt.jar */
+ InputStream is = loader.getResourceAsStream ("javax/swing/text/rtf/charsets/mac.txt");
+ if (is == null) {
+ System.out.println ("could not find mac.txt");
+ return;
+ }
+ int c=0;
+ while ((is.read()) != -1) {
+ c++;
+ }
+ if (c == 26) /* size of bad file */ {
+ throw new RuntimeException ("Wrong mac.txt file was loaded");
+ }
+ }
+}
diff --git a/test/java/net/URLClassLoader/B5077773.sh b/test/java/net/URLClassLoader/B5077773.sh
new file mode 100644
index 0000000..6dcba9c
--- /dev/null
+++ b/test/java/net/URLClassLoader/B5077773.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+
+#
+# Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# @test
+# @author Michael McMahon
+# @bug 5077773
+# @summary Change in behaviour w.r.t jdk1.4.2 when loading resourcebundles
+#
+# ${TESTJAVA} is pointing to the jre
+#
+# set platform-dependent variables
+
+OS=`uname -s`
+case "$OS" in
+ SunOS )
+ PS=":"
+ FS="/"
+ ;;
+ Linux )
+ PS=":"
+ FS="/"
+ ;;
+ Windows* )
+ PS=";"
+ FS="\\"
+ ;;
+ * )
+ echo "Unrecognized system!"
+ exit 1;
+ ;;
+esac
+
+cp ${TESTSRC}${FS}foo.jar .
+
+${TESTJAVA}${FS}bin${FS}javac -d . ${TESTSRC}${FS}B5077773.java
+
+WD=`pwd`
+${TESTJAVA}${FS}bin${FS}java B5077773
+
diff --git a/test/java/net/URLClassLoader/ClassLoad.java b/test/java/net/URLClassLoader/ClassLoad.java
new file mode 100644
index 0000000..5870191
--- /dev/null
+++ b/test/java/net/URLClassLoader/ClassLoad.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4151665
+ * @summary Test for FileNotFoundException when loading bogus class
+ */
+
+import java.net.*;
+import java.io.*;
+
+public class ClassLoad {
+ public static void main(String[] args) throws Exception {
+ boolean error = true;
+ try {
+ URL url = new URL(args.length >= 1 ? args[0] : "http://jini.east/");
+ String name = args.length >= 2 ? args[1] : "foo.bar.Baz";
+ ClassLoader loader = new URLClassLoader(new URL[] { url });
+ Class c = loader.loadClass(name);
+ System.out.println("Loaded class \"" + c.getName() + "\".");
+ } catch (ClassNotFoundException ex) {
+ error = false;
+ }
+ if (error)
+ throw new RuntimeException("No ClassNotFoundException generated");
+ }
+}
diff --git a/test/java/net/URLClassLoader/ClassPathTest.java b/test/java/net/URLClassLoader/ClassPathTest.java
new file mode 100644
index 0000000..6da24f6
--- /dev/null
+++ b/test/java/net/URLClassLoader/ClassPathTest.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4110602
+ * @author Benjamin Renaud
+ * @summary check that URLClassLoader correctly interprets Class-Path
+ *
+ * This test ensures that a manually constructed URLClassLoader is
+ * able to:
+ *
+ * 1. load a class
+ * 2. resolve Class-Path dependencies
+ * 3. have that class use a dependent class in a different JAR file
+ */
+import java.util.jar.*;
+import java.util.*;
+import java.io.*;
+import java.net.*;
+
+public class ClassPathTest {
+
+ JarFile jarFile;
+ Manifest manifest;
+ Attributes mainAttributes;
+ Map map;
+ URLClassLoader ucl;
+
+ static class TestException extends RuntimeException {
+ TestException(Throwable t) {
+ super("URLClassLoader ClassPathTest failed with: " + t);
+ }
+ }
+
+ public ClassPathTest() {
+ File local = new File(System.getProperty("test.src", "."),
+ "jars/class_path_test.jar");
+ String jarFileName = local.getPath();
+
+ try {
+ jarFile = new JarFile(jarFileName);
+ }
+ catch (IOException e) {
+ System.err.println("Could not find jar file " + jarFileName);
+ throw new TestException(e);
+ }
+ try {
+ URL url = getUrl(new File(jarFileName));
+ System.out.println("url: " + url);
+
+ ucl = new URLClassLoader(new URL[] { url });
+
+ // Moved this inside try block, as it may raise IOException.
+ // (maddox)
+ manifest = jarFile.getManifest();
+ }
+ catch (Exception e) {
+ throw new TestException(e);
+ }
+ //manifest = jarFile.getManifest();
+ mainAttributes = manifest.getMainAttributes();
+ map = manifest.getEntries();
+
+ Iterator it = map.entrySet().iterator();
+ Class clazz = null;
+
+ while (it.hasNext()) {
+ Map.Entry e = (Map.Entry)it.next();
+ Attributes a = (Attributes)e.getValue();
+
+ Attributes.Name an = new Attributes.Name("Class-Path");
+ if (a.containsKey(an)) {
+ String val = a.getValue(an);
+ if (val != null)
+ System.out.println("Class-Path: " + val);
+ }
+
+ if (a.containsKey(new Attributes.Name("Java-Bean"))) {
+
+ String beanClassName = nameToClassName((String)e.getKey());
+ System.out.println("JavaBean Class: " + beanClassName);
+
+ try {
+ clazz = ucl.loadClass(beanClassName);
+ }
+ catch (Throwable t) {
+ throw new TestException(t);
+ } if (clazz != null) {
+ try {
+ System.out.println("instantiating " + beanClassName);
+ clazz.newInstance();
+ System.out.println("done instantiating " +
+ beanClassName);
+ } catch (Throwable t2) {
+ throw new TestException(t2);
+ }
+ }
+ }
+ }
+ }
+
+ String nameToClassName(String key) {
+ String key2 = key.replace('/', File.separatorChar);
+ int li = key2.lastIndexOf(".class");
+ key2 = key2.substring(0, li);
+ return key2;
+ }
+
+ private static URL getUrl(File file) {
+ String name;
+ try {
+ name = file.getCanonicalPath();
+ } catch (IOException e) {
+ name = file.getAbsolutePath();
+ }
+ name = name.replace(File.separatorChar, '/');
+ if (!name.startsWith("/")) {
+ name = "/" + name;
+ }
+ try {
+ return new URL( "file:" + name);
+ } catch (MalformedURLException e) {
+ throw new TestException(e);
+ }
+ }
+
+ public static void main(String args[]) {
+ new ClassPathTest();
+ }
+}
diff --git a/test/java/net/URLClassLoader/GetURLsTest.java b/test/java/net/URLClassLoader/GetURLsTest.java
new file mode 100644
index 0000000..99b91d9
--- /dev/null
+++ b/test/java/net/URLClassLoader/GetURLsTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.net.*;
+import java.io.*;
+
+/*
+ * Regression test for URLClassLoader getURLs() and addURL() methods.
+ * See RFE 4102580: Need URLClassLoader.getURLs() method
+ */
+class GetURLsTest {
+ public static void main(String[] args) throws Exception {
+ MyURLClassLoader ucl =
+ new MyURLClassLoader(new URL[] { new File(".").toURL() });
+ p("initial urls = ", ucl.getURLs());
+ URL u = ucl.getResource("GetURLsTest.java");
+ if (u != null) {
+ p("found resource = " + u);
+ }
+ ucl.addURL(new File("jars", "class_path_test.jar").toURL());
+ p("new urls = ", ucl.getURLs());
+ Class c = ucl.loadClass("Foo");
+ p("found class = " + c);
+ }
+
+ static class MyURLClassLoader extends URLClassLoader {
+ public MyURLClassLoader(URL[] urls) {
+ super(urls);
+ }
+ public void addURL(URL url) {
+ super.addURL(url);
+ }
+ }
+
+ static void p(String s, URL[] urls) {
+ System.out.print(s);
+ if (urls.length > 0) {
+ for (int i = 0; i < urls.length - 1; i++) {
+ System.out.print(urls[i] + " ");
+ }
+ }
+ System.out.println(urls[urls.length - 1]);
+ }
+
+ static void p(String s) {
+ System.out.println(s);
+ }
+}
diff --git a/test/java/net/URLClassLoader/HttpTest.java b/test/java/net/URLClassLoader/HttpTest.java
new file mode 100644
index 0000000..e04331f
--- /dev/null
+++ b/test/java/net/URLClassLoader/HttpTest.java
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4636331
+ * @summary Check that URLClassLoader doesn't create excessive http
+ * connections
+ */
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+public class HttpTest {
+
+ /*
+ * Simple http server to service http requests. Auto shutdown
+ * if "idle" (no requests) for 10 seconds. Forks worker thread
+ * to service persistent connections. Work threads shutdown if
+ * "idle" for 5 seconds.
+ */
+ static class HttpServer implements Runnable {
+
+ private static HttpServer svr = null;
+ private static Counters cnts = null;
+ private static ServerSocket ss;
+
+ private static Object counterLock = new Object();
+ private static int getCount = 0;
+ private static int headCount = 0;
+
+ class Worker extends Thread {
+ Socket s;
+ Worker(Socket s) {
+ this.s = s;
+ }
+
+ public void run() {
+ try {
+
+ InputStream in = s.getInputStream();
+ for (;;) {
+
+ // read entire request from client
+ byte b[] = new byte[1024];
+ int n, total=0;
+
+ // max 5 seconds to wait for new request
+ s.setSoTimeout(5000);
+ try {
+ do {
+ n = in.read(b, total, b.length-total);
+ // max 0.5 seconds between each segment
+ // of request.
+ s.setSoTimeout(500);
+ if (n > 0) total += n;
+ } while (n > 0);
+ } catch (SocketTimeoutException e) { }
+
+ if (total == 0) {
+ s.close();
+ return;
+ }
+
+ boolean getRequest = false;
+ if (b[0] == 'G' && b[1] == 'E' && b[2] == 'T')
+ getRequest = true;
+
+ synchronized (counterLock) {
+ if (getRequest)
+ getCount++;
+ else
+ headCount++;
+ }
+
+ // response to client
+ PrintStream out = new PrintStream(
+ new BufferedOutputStream(
+ s.getOutputStream() ));
+ out.print("HTTP/1.1 200 OK\r\n");
+
+ out.print("Content-Length: 75000\r\n");
+ out.print("\r\n");
+ if (getRequest) {
+ for (int i=0; i<75*1000; i++) {
+ out.write( (byte)'.' );
+ }
+ }
+ out.flush();
+
+ } // for
+
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ HttpServer() throws Exception {
+ ss = new ServerSocket(0);
+ }
+
+ public void run() {
+ try {
+ // shutdown if no request in 10 seconds.
+ ss.setSoTimeout(10000);
+ for (;;) {
+ Socket s = ss.accept();
+ (new Worker(s)).start();
+ }
+ } catch (Exception e) {
+ }
+ }
+
+ public static HttpServer create() throws Exception {
+ if (svr != null)
+ return svr;
+ cnts = new Counters();
+ svr = new HttpServer();
+ (new Thread(svr)).start();
+ return svr;
+ }
+
+ public static void shutdown() throws Exception {
+ if (svr != null) {
+ ss.close();
+ svr = null;
+ }
+ }
+
+ public int port() {
+ return ss.getLocalPort();
+ }
+
+ public static class Counters {
+ public void reset() {
+ synchronized (counterLock) {
+ getCount = 0;
+ headCount = 0;
+ }
+ }
+
+ public int getCount() {
+ synchronized (counterLock) {
+ return getCount;
+ }
+ }
+
+ public int headCount() {
+ synchronized (counterLock) {
+ return headCount;
+ }
+ }
+
+ public String toString() {
+ synchronized (counterLock) {
+ return "GET count: " + getCount + "; " +
+ "HEAD count: " + headCount;
+ }
+ }
+ }
+
+ public Counters counters() {
+ return cnts;
+ }
+
+ }
+
+ public static void main(String args[]) throws Exception {
+ boolean failed = false;
+
+ // create http server
+ HttpServer svr = HttpServer.create();
+
+ // create class loader
+ URL urls[] =
+ { new URL("http://localhost:" + svr.port() + "/dir1/"),
+ new URL("http://localhost:" + svr.port() + "/dir2/") };
+ URLClassLoader cl = new URLClassLoader(urls);
+
+ // Test 1 - check that getResource does single HEAD request
+ svr.counters().reset();
+ URL url = cl.getResource("foo.gif");
+ System.out.println(svr.counters());
+
+ if (svr.counters().getCount() > 0 ||
+ svr.counters().headCount() > 1) {
+ failed = true;
+ }
+
+ // Test 2 - check that getResourceAsStream does at most
+ // one GET request
+ svr.counters().reset();
+ InputStream in = cl.getResourceAsStream("foo2.gif");
+ System.out.println(svr.counters());
+ if (svr.counters().getCount() > 1) {
+ failed = true;
+ }
+
+ // Test 3 - check that getResources only does HEAD requests
+ svr.counters().reset();
+ Enumeration e = cl.getResources("foos.gif");
+ try {
+ for (;;) {
+ e.nextElement();
+ }
+ } catch (NoSuchElementException exc) { }
+ System.out.println(svr.counters());
+ if (svr.counters().getCount() > 1) {
+ failed = true;
+ }
+
+ // shutdown http server
+ svr.shutdown();
+
+ if (failed) {
+ throw new Exception("Excessive http connections established - Test failed");
+ }
+ }
+
+}
diff --git a/test/java/net/URLClassLoader/URLParsing.java b/test/java/net/URLClassLoader/URLParsing.java
new file mode 100644
index 0000000..254c020
--- /dev/null
+++ b/test/java/net/URLClassLoader/URLParsing.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4128326 4127567
+ * @summary Test URL parsing
+ *
+ */
+
+import java.net.*;
+import java.io.*;
+
+public class URLParsing {
+
+ public static void main(String[] args) throws Exception {
+ File local = new File(System.getProperty("test.src", "."), "jars");
+ String path = "jar:file:"
+ + local.getPath()
+ + "/class_path_test.jar!/Foo.java";
+
+ URL aURL = new URL(path);
+ URL testURL = new URL(aURL, "foo/../Foo.java");
+
+ InputStream in = testURL.openStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ String firstLine = reader.readLine();
+ if (!firstLine.startsWith("public class Foo {"))
+ throw new RuntimeException("Jar or File parsing failure.");
+
+ }
+}
diff --git a/test/java/net/URLClassLoader/extdir/extention.jar b/test/java/net/URLClassLoader/extdir/extention.jar
new file mode 100644
index 0000000..f4d9600
--- /dev/null
+++ b/test/java/net/URLClassLoader/extdir/extention.jar
Binary files differ
diff --git a/test/java/net/URLClassLoader/getresourceasstream/Test.java b/test/java/net/URLClassLoader/getresourceasstream/Test.java
new file mode 100644
index 0000000..14ba54e
--- /dev/null
+++ b/test/java/net/URLClassLoader/getresourceasstream/Test.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.net.*;
+import java.io.*;
+
+public class Test {
+ public static void main (String[] args) throws Exception {
+ test1();
+ }
+
+ public static void test1 () throws Exception {
+ URLClassLoader cl = new URLClassLoader (new URL[] {
+ new URL ("file:./test.jar")
+ });
+ Class clazz = Class.forName ("Test\u00a3", true, cl);
+ InputStream is = clazz.getResourceAsStream ("Test\u00a3.class");
+ is.read();
+ is = clazz.getResourceAsStream ("Rest\u00a3.class");
+ is.read();
+ }
+}
diff --git a/test/java/net/URLClassLoader/getresourceasstream/test.jar b/test/java/net/URLClassLoader/getresourceasstream/test.jar
new file mode 100644
index 0000000..e0a6f5f
--- /dev/null
+++ b/test/java/net/URLClassLoader/getresourceasstream/test.jar
Binary files differ
diff --git a/test/java/net/URLClassLoader/getresourceasstream/test.sh b/test/java/net/URLClassLoader/getresourceasstream/test.sh
new file mode 100644
index 0000000..112c157
--- /dev/null
+++ b/test/java/net/URLClassLoader/getresourceasstream/test.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+#
+# Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+set -x
+# @test
+# @bug 5103449
+# @run shell test.sh
+# @summary REGRESSION: getResourceAsStream is broken in JDK1.5.0-rc
+#
+
+
+cat << POLICY > policy
+grant {
+ permission java.lang.RuntimePermission "createClassLoader";
+};
+POLICY
+
+checkExit () {
+ if [ $? != 0 ]; then
+ exit 1;
+ fi
+}
+
+${TESTJAVA}/bin/javac -d . ${TESTSRC}/Test.java
+cp ${TESTSRC}/test.jar .
+
+${TESTJAVA}/bin/java Test
+checkExit
+
+# try with security manager
+
+${TESTJAVA}/bin/java -Djava.security.policy=file:./policy -Djava.security.manager Test
+checkExit
+exit 0
diff --git a/test/java/net/URLClassLoader/jars/class_path_test.jar b/test/java/net/URLClassLoader/jars/class_path_test.jar
new file mode 100644
index 0000000..ac5ee20
--- /dev/null
+++ b/test/java/net/URLClassLoader/jars/class_path_test.jar
Binary files differ
diff --git a/test/java/net/URLClassLoader/jars/class_path_test_classpath.jar b/test/java/net/URLClassLoader/jars/class_path_test_classpath.jar
new file mode 100644
index 0000000..26486f0
--- /dev/null
+++ b/test/java/net/URLClassLoader/jars/class_path_test_classpath.jar
Binary files differ
diff --git a/test/java/net/URLClassLoader/sealing/CheckSealed.java b/test/java/net/URLClassLoader/sealing/CheckSealed.java
new file mode 100644
index 0000000..38d8242
--- /dev/null
+++ b/test/java/net/URLClassLoader/sealing/CheckSealed.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4244970
+ * @summary Test to see if sealing violation is detected correctly
+ * @run shell checksealed.sh
+ *
+ */
+public class CheckSealed {
+
+ public static void main(String[] argv) throws Exception {
+ boolean fail = true;
+ try {
+ if ("1".equals(argv[0])) {
+ test1();
+ test2();
+ } else if ("2".equals(argv[0])) {
+ test2();
+ test1();
+ }
+ } catch (java.lang.SecurityException e) {
+ fail = false;
+ }
+ if (fail) {
+ throw new Exception("Sealing violation undetected.");
+ }
+ }
+
+ private static void test1() {
+ p.A.hello();
+ }
+
+ private static void test2() {
+ p.B.hello();
+ }
+}
diff --git a/test/java/net/URLClassLoader/sealing/Makefile b/test/java/net/URLClassLoader/sealing/Makefile
new file mode 100644
index 0000000..fc8ec81
--- /dev/null
+++ b/test/java/net/URLClassLoader/sealing/Makefile
@@ -0,0 +1,17 @@
+#
+
+# This makefile is only used to update b.jar and directory a,
+# which are checked in to SCCS.
+
+JBIN=../../../../../build/solaris/bin
+
+all: b.jar
+
+b.jar: classes
+ $(JBIN)/jar cmf manifest b.jar -C b p/B.class
+
+classes:
+ $(JBIN)/javac -sourcepath a:b ?/p/*.java
+
+clean:
+ rm -rf b.jar ?/p/*.class
diff --git a/test/java/net/URLClassLoader/sealing/a/p/A.java b/test/java/net/URLClassLoader/sealing/a/p/A.java
new file mode 100644
index 0000000..3e6bc08
--- /dev/null
+++ b/test/java/net/URLClassLoader/sealing/a/p/A.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
+package p;
+
+public class A {
+
+ public static void hello() {
+ System.out.println("A");
+ }
+
+}
diff --git a/test/java/net/URLClassLoader/sealing/b.jar b/test/java/net/URLClassLoader/sealing/b.jar
new file mode 100644
index 0000000..133c5e2
--- /dev/null
+++ b/test/java/net/URLClassLoader/sealing/b.jar
Binary files differ
diff --git a/test/java/net/URLClassLoader/sealing/b/p/B.java b/test/java/net/URLClassLoader/sealing/b/p/B.java
new file mode 100644
index 0000000..99080c8
--- /dev/null
+++ b/test/java/net/URLClassLoader/sealing/b/p/B.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+
+package p;
+
+public class B {
+
+ public static void hello() {
+ System.out.println("B");
+ }
+
+}
diff --git a/test/java/net/URLClassLoader/sealing/checksealed.sh b/test/java/net/URLClassLoader/sealing/checksealed.sh
new file mode 100644
index 0000000..e46ac29
--- /dev/null
+++ b/test/java/net/URLClassLoader/sealing/checksealed.sh
@@ -0,0 +1,58 @@
+#! /bin/sh
+
+#
+# Copyright 1999-2002 Sun Microsystems, Inc. All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+#
+
+OS=`uname -s`
+case "$OS" in
+ SunOS )
+ PS=":"
+ FS="/"
+ ;;
+ Linux )
+ PS=":"
+ FS="/"
+ ;;
+ Windows* )
+ PS=";"
+ FS="\\"
+ ;;
+ * )
+ echo "Unrecognized system!"
+ exit 1;
+ ;;
+esac
+
+
+if [ x"$TESTJAVA" = x ]; then TESTJAVA=$1; fi
+if [ x"$TESTSRC" = x ]; then TESTSRC=.; fi
+
+CLASSPATH=.${PS}${TESTSRC}${FS}a${PS}${TESTSRC}${FS}b.jar
+
+${TESTJAVA}${FS}bin${FS}javac -classpath ${CLASSPATH} -d . ${TESTSRC}${FS}CheckSealed.java
+${TESTJAVA}${FS}bin${FS}java -cp ${CLASSPATH} CheckSealed 1
+if [ $? != 0 ]; then exit 1; fi
+${TESTJAVA}${FS}bin${FS}java -cp ${CLASSPATH} CheckSealed 2
+if [ $? != 0 ]; then exit 1; fi
diff --git a/test/java/net/URLClassLoader/sealing/manifest b/test/java/net/URLClassLoader/sealing/manifest
new file mode 100644
index 0000000..b6b37f4
--- /dev/null
+++ b/test/java/net/URLClassLoader/sealing/manifest
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Sealed: true
+