Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/misc/URLClassPath/ClassnameCharTest.java
38838 views
1
/*
2
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
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
*
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.
22
*/
23
24
/* @test
25
* @bug 4957669 5017871
26
* @compile -XDignore.symbol.file=true ClassnameCharTest.java
27
* @run main ClassnameCharTest
28
* @summary cannot load class names containing some JSR 202 characters;
29
* plugin does not escape unicode character in http request
30
*/
31
32
import java.io.*;
33
import java.net.*;
34
import java.util.jar.*;
35
import com.sun.net.httpserver.*;
36
import sun.applet.AppletClassLoader;
37
38
public class ClassnameCharTest {
39
static String FNPrefix = System.getProperty("test.src", ".") + File.separator;
40
static File classesJar = new File(FNPrefix + "testclasses.jar");
41
static HttpServer server;
42
43
public static void realMain(String[] args) throws Exception {
44
server = HttpServer.create(new InetSocketAddress(0), 0);
45
server.createContext("/", new HttpHandler() {
46
@Override
47
public void handle(HttpExchange exchange) {
48
try {
49
String filename = exchange.getRequestURI().getPath();
50
System.out.println("getRequestURI = " + exchange.getRequestURI());
51
System.out.println("filename = " + filename);
52
try (FileInputStream fis = new FileInputStream(classesJar);
53
JarInputStream jis = new JarInputStream(fis)) {
54
JarEntry entry;
55
while ((entry = jis.getNextJarEntry()) != null) {
56
if (filename.endsWith(entry.getName())) {
57
ByteArrayOutputStream baos = new ByteArrayOutputStream();
58
byte[] buf = new byte[8092];
59
int count = 0;
60
while ((count = jis.read(buf)) != -1)
61
baos.write(buf, 0, count);
62
exchange.sendResponseHeaders(200, baos.size());
63
try (OutputStream os = exchange.getResponseBody()) {
64
baos.writeTo(os);
65
}
66
return;
67
}
68
}
69
fail("Failed to find " + filename);
70
}
71
} catch (IOException e) {
72
unexpected(e);
73
}
74
}
75
});
76
server.start();
77
try {
78
URL base = new URL("http://localhost:" + server.getAddress().getPort());
79
System.out.println ("Server: listening on " + base);
80
MyAppletClassLoader acl = new MyAppletClassLoader(base);
81
Class<?> class1 = acl.findClass("fo o");
82
System.out.println("class1 = " + class1);
83
pass();
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);
87
} finally {
88
server.stop(0);
89
}
90
}
91
92
static class MyAppletClassLoader extends AppletClassLoader {
93
MyAppletClassLoader(URL base) {
94
super(base);
95
}
96
97
@Override
98
public Class<?> findClass(String name) throws ClassNotFoundException {
99
return super.findClass(name);
100
}
101
}
102
103
//--------------------- Infrastructure ---------------------------
104
static volatile int passed = 0, failed = 0;
105
106
static boolean pass() {
107
passed++;
108
return true;
109
}
110
111
static boolean fail() {
112
failed++;
113
if (server != null) {
114
server.stop(0);
115
}
116
Thread.dumpStack();
117
return false;
118
}
119
120
static boolean fail(String msg) {
121
System.out.println(msg);
122
return fail();
123
}
124
125
static void unexpected(Throwable t) {
126
failed++;
127
if (server != null) {
128
server.stop(0);
129
}
130
t.printStackTrace();
131
}
132
133
static boolean check(boolean cond) {
134
if (cond) {
135
pass();
136
} else {
137
fail();
138
}
139
return cond;
140
}
141
142
static boolean equal(Object x, Object y) {
143
if (x == null ? y == null : x.equals(y)) {
144
return pass();
145
} else {
146
return fail(x + " not equal to " + y);
147
}
148
}
149
150
public static void main(String[] args) throws Throwable {
151
try {
152
realMain(args);
153
} catch (Throwable t) {
154
unexpected(t);
155
}
156
System.out.println("\nPassed = " + passed + " failed = " + failed);
157
if (failed > 0) {
158
throw new AssertionError("Some tests failed");
159
}
160
}
161
}
162
163