author | ihse |
Mon, 09 Mar 2015 10:39:16 +0100 | |
changeset 29304 | 81a723f8d33c |
parent 13798 | b2438779f375 |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
24 |
/* @test |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
25 |
* @bug 4957669 5017871 |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
26 |
* @compile -XDignore.symbol.file=true ClassnameCharTest.java |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
27 |
* @run main ClassnameCharTest |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
28 |
* @summary cannot load class names containing some JSR 202 characters; |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
29 |
* plugin does not escape unicode character in http request |
2 | 30 |
*/ |
31 |
||
32 |
import java.io.*; |
|
33 |
import java.net.*; |
|
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
34 |
import java.util.jar.*; |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
35 |
import com.sun.net.httpserver.*; |
2 | 36 |
import sun.applet.AppletClassLoader; |
37 |
||
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
38 |
public class ClassnameCharTest { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
39 |
static String FNPrefix = System.getProperty("test.src", ".") + File.separator; |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
40 |
static File classesJar = new File(FNPrefix + "testclasses.jar"); |
2 | 41 |
static HttpServer server; |
42 |
||
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
43 |
public static void realMain(String[] args) throws Exception { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
44 |
server = HttpServer.create(new InetSocketAddress(0), 0); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
45 |
server.createContext("/", new HttpHandler() { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
46 |
@Override |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
47 |
public void handle(HttpExchange exchange) { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
48 |
try { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
49 |
String filename = exchange.getRequestURI().getPath(); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
50 |
System.out.println("getRequestURI = " + exchange.getRequestURI()); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
51 |
System.out.println("filename = " + filename); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
52 |
try (FileInputStream fis = new FileInputStream(classesJar); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
53 |
JarInputStream jis = new JarInputStream(fis)) { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
54 |
JarEntry entry; |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
55 |
while ((entry = jis.getNextJarEntry()) != null) { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
56 |
if (filename.endsWith(entry.getName())) { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
57 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
58 |
byte[] buf = new byte[8092]; |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
59 |
int count = 0; |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
60 |
while ((count = jis.read(buf)) != -1) |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
61 |
baos.write(buf, 0, count); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
62 |
exchange.sendResponseHeaders(200, baos.size()); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
63 |
try (OutputStream os = exchange.getResponseBody()) { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
64 |
baos.writeTo(os); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
65 |
} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
66 |
return; |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
67 |
} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
68 |
} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
69 |
fail("Failed to find " + filename); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
70 |
} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
71 |
} catch (IOException e) { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
72 |
unexpected(e); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
73 |
} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
74 |
} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
75 |
}); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
76 |
server.start(); |
2 | 77 |
try { |
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
78 |
URL base = new URL("http://localhost:" + server.getAddress().getPort()); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
79 |
System.out.println ("Server: listening on " + base); |
2 | 80 |
MyAppletClassLoader acl = new MyAppletClassLoader(base); |
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
81 |
Class<?> class1 = acl.findClass("fo o"); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
82 |
System.out.println("class1 = " + class1); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
83 |
pass(); |
2 | 84 |
// can't test the following class unless platform in unicode locale |
85 |
// Class class2 = acl.findClass("\u624b\u518c"); |
|
86 |
// System.out.println("class2 = "+class2); |
|
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
87 |
} finally { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
88 |
server.stop(0); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
89 |
} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
90 |
} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
91 |
|
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
92 |
static class MyAppletClassLoader extends AppletClassLoader { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
93 |
MyAppletClassLoader(URL base) { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
94 |
super(base); |
2 | 95 |
} |
96 |
||
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
97 |
@Override |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
98 |
public Class<?> findClass(String name) throws ClassNotFoundException { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
99 |
return super.findClass(name); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
100 |
} |
2 | 101 |
} |
102 |
||
13798
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
103 |
//--------------------- Infrastructure --------------------------- |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
104 |
static volatile int passed = 0, failed = 0; |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
105 |
static boolean pass() {passed++; return true;} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
106 |
static boolean fail() {failed++; server.stop(0); Thread.dumpStack(); return false;} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
107 |
static boolean fail(String msg) {System.out.println(msg); return fail();} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
108 |
static void unexpected(Throwable t) {failed++; server.stop(0); t.printStackTrace();} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
109 |
static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
110 |
static boolean equal(Object x, Object y) { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
111 |
if (x == null ? y == null : x.equals(y)) return pass(); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
112 |
else return fail(x + " not equal to " + y);} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
113 |
public static void main(String[] args) throws Throwable { |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
114 |
try {realMain(args);} catch (Throwable t) {unexpected(t);} |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
115 |
System.out.println("\nPassed = " + passed + " failed = " + failed); |
b2438779f375
7197203: sun/misc/URLClassPath/ClassnameCharTest.sh failed, compile error
chegar
parents:
5506
diff
changeset
|
116 |
if (failed > 0) throw new AssertionError("Some tests failed");} |
2 | 117 |
} |