Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/URL/Constructor.java
41149 views
1
/*
2
* Copyright (c) 1998, 2013, 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
/*
25
* @test
26
* @bug 4393671
27
* @summary URL constructor URL(URL context, String spec) FAILED with specific input
28
*/
29
30
/*
31
* This program tests the URL parser in the URL constructor. It
32
* tries to construct a variety of valid URLs with a given context
33
* (which may be null) and a variety of specs. It then compares the
34
* result with an expected value.
35
*/
36
37
import java.net.MalformedURLException;
38
import java.net.URL;
39
import java.util.ArrayList;
40
import java.util.Arrays;
41
import java.util.List;
42
43
public class Constructor {
44
45
public static void main(String[] args) throws Exception {
46
List<Entry> entries = new ArrayList<>();
47
entries.addAll(Arrays.asList(fileURLs));
48
entries.addAll(Arrays.asList(jarURLs));
49
entries.addAll(Arrays.asList(normalHttpURLs));
50
entries.addAll(Arrays.asList(abnormalHttpURLs));
51
if (hasFtp())
52
entries.addAll(Arrays.asList(ftpURLs));
53
URL url;
54
55
for (Entry e : entries) {
56
if (e.context == null)
57
url = new URL(e.spec);
58
else
59
url = new URL(new URL(e.context), e.spec);
60
61
if (!(url.toString().equals(e.expected))) {
62
throw new RuntimeException("error for: \n\tURL:" + e.context +
63
"\n\tspec: " + e.spec +
64
"\n\texpected: " + e.expected +
65
"\n\tactual: " + url.toString());
66
} else {
67
//debug
68
//System.out.println("success for: " + url);
69
}
70
}
71
}
72
73
private static boolean hasFtp() {
74
try {
75
return new java.net.URL("ftp://") != null;
76
} catch (java.net.MalformedURLException x) {
77
System.out.println("FTP not supported by this runtime.");
78
return false;
79
}
80
}
81
82
static class Entry {
83
final String context;
84
final String spec;
85
final String expected;
86
Entry(String context, String spec, String expected) {
87
this.context = context;
88
this.spec =spec;
89
this.expected = expected;
90
}
91
}
92
93
static Entry[] fileURLs = new Entry[] {
94
new Entry(null,
95
"file://JavaSoft/Test",
96
"file://JavaSoft/Test"),
97
new Entry(null,
98
"file:///JavaSoft/Test",
99
"file:/JavaSoft/Test"),
100
new Entry(null,
101
"file:/JavaSoft/Test",
102
"file:/JavaSoft/Test"),
103
new Entry(null,
104
"file:/c:/JavaSoft/Test",
105
"file:/c:/JavaSoft/Test"),
106
new Entry(null,
107
"file:/c:/JavaSoft/Test:something",
108
"file:/c:/JavaSoft/Test:something"),
109
new Entry(null,
110
"file:/c:/JavaSoft/Test#anchor",
111
"file:/c:/JavaSoft/Test#anchor"),
112
new Entry("file://JavaSoft/Test",
113
"Test#bar",
114
"file://JavaSoft/Test#bar"),
115
new Entry("file://codrus/c:/jdk/eng/index.html",
116
"pulsar.html",
117
"file://codrus/c:/jdk/eng/pulsar.html"),
118
new Entry("file:///c:/jdk/eng/index.html",
119
"pulsar.html",
120
"file:/c:/jdk/eng/pulsar.html"),
121
new Entry("file:///jdk/eng/index.html",
122
"pulsar.html",
123
"file:/jdk/eng/pulsar.html"),
124
new Entry("file://JavaSoft/Test",
125
"file://radartoad.com/Test#bar",
126
"file://radartoad.com/Test#bar"),
127
new Entry("file://JavaSoft/Test",
128
"/c:/Test#bar",
129
"file://JavaSoft/c:/Test#bar"),
130
};
131
132
static Entry[] jarURLs = new Entry[] {
133
new Entry(null,
134
"jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt",
135
"jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt"),
136
new Entry(null,
137
"jar:http://www.foo.com/dir1/jar.jar!/",
138
"jar:http://www.foo.com/dir1/jar.jar!/"),
139
new Entry(null,
140
"jar:http://www.foo.com/dir1/jar.jar!/",
141
"jar:http://www.foo.com/dir1/jar.jar!/"),
142
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
143
"entry.txt",
144
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
145
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
146
"/entry.txt",
147
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
148
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
149
"dir1/entry.txt",
150
"jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
151
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
152
"/dir1/entry.txt",
153
"jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
154
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
155
"entry.txt",
156
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
157
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
158
"/entry.txt",
159
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
160
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
161
"/entry.txt",
162
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
163
new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir1/",
164
"entry.txt",
165
"jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
166
new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir2/dir3/entry2.txt",
167
"/dir1/entry.txt",
168
"jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
169
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
170
"/dir1/foo/entry.txt",
171
"jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt"),
172
new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/",
173
"dir4/foo/entry.txt",
174
"jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/dir4/foo/entry.txt"),
175
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
176
"/dir1/foo/entry.txt",
177
"jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt"),
178
new Entry(null,
179
"jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor",
180
"jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor"),
181
new Entry("jar:http://www.foo.com/dir1/jar.jar!/foo.txt",
182
"#anchor",
183
"jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor"),
184
new Entry("jar:http://www.foo.com/dir1/jar.jar!/foo/bar/",
185
"baz/quux#anchor",
186
"jar:http://www.foo.com/dir1/jar.jar!/foo/bar/baz/quux#anchor"),
187
new Entry("jar:http://balloo.com/olle.jar!/",
188
"p2",
189
"jar:http://balloo.com/olle.jar!/p2")
190
};
191
192
static Entry[] normalHttpURLs = new Entry[] {
193
new Entry("http://a/b/c/d;p?q", "g", "http://a/b/c/g"),
194
new Entry("http://a/b/c/d;p?q", "./g", "http://a/b/c/g"),
195
new Entry("http://a/b/c/d;p?q", "g/", "http://a/b/c/g/"),
196
new Entry("http://a/b/c/d;p?q", "/g", "http://a/g"),
197
new Entry("http://a/b/c/d;p?q", "//g", "http://g"),
198
new Entry("http://a/b/c/d;p?q", "?y", "http://a/b/c/?y"),
199
new Entry("http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y"),
200
new Entry("http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s"),
201
new Entry("http://a/b/c/d;p?q", "g?y#s", "http://a/b/c/g?y#s"),
202
new Entry("http://a/b/c/d;p?q", ";x", "http://a/b/c/;x"),
203
new Entry("http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x"),
204
new Entry("http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s"),
205
new Entry("http://a/b/c/d;p?q", ".", "http://a/b/c/"),
206
new Entry("http://a/b/c/d;p?q", "./", "http://a/b/c/"),
207
new Entry("http://a/b/c/d;p?q", "..", "http://a/b/"),
208
new Entry("http://a/b/c/d;p?q", "../", "http://a/b/"),
209
new Entry("http://a/b/c/d;p?q", "../g", "http://a/b/g"),
210
new Entry("http://a/b/c/d;p?q", "../..", "http://a/"),
211
new Entry("http://a/b/c/d;p?q", "../../", "http://a/"),
212
new Entry("http://a/b/c/d;p?q", "../../g", "http://a/g"),
213
new Entry(null,
214
"http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc",
215
"http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc")
216
};
217
218
static Entry[] abnormalHttpURLs = new Entry[] {
219
new Entry("http://a/b/c/d;p?q", "../../../g", "http://a/../g"),
220
new Entry("http://a/b/c/d;p?q", "../../../../g", "http://a/../../g"),
221
new Entry("http://a/b/c/d;p?q", "/./g", "http://a/./g"),
222
new Entry("http://a/b/c/d;p?q", "/../g", "http://a/../g"),
223
new Entry("http://a/b/c/d;p?q", ".g", "http://a/b/c/.g"),
224
new Entry("http://a/b/c/d;p?q", "g.", "http://a/b/c/g."),
225
new Entry("http://a/b/c/d;p?q", "./../g", "http://a/b/g"),
226
new Entry("http://a/b/c/d;p?q", "./g/.", "http://a/b/c/g/"),
227
new Entry("http://a/b/c/d;p?q", "g/./h", "http://a/b/c/g/h"),
228
new Entry("http://a/b/c/d;p?q", "g;x=1/./y", "http://a/b/c/g;x=1/y"),
229
new Entry("http://a/b/c/d;p?q", "g;x=1/../y", "http://a/b/c/y")
230
};
231
232
static Entry[] ftpURLs = new Entry[] {
233
new Entry(null,
234
"ftp://ftp.foo.com/dir1/entry.txt",
235
"ftp://ftp.foo.com/dir1/entry.txt"),
236
new Entry(null,
237
"ftp://br:[email protected]/dir1/jar.jar",
238
"ftp://br:[email protected]/dir1/jar.jar"),
239
new Entry("ftp://ftp.foo.com/dir1/foo.txt",
240
"bar.txt",
241
"ftp://ftp.foo.com/dir1/bar.txt"),
242
new Entry("ftp://ftp.foo.com/dir1/jar.jar",
243
"/entry.txt",
244
"ftp://ftp.foo.com/entry.txt"),
245
new Entry("ftp://ftp.foo.com/dir1/jar.jar",
246
"dir1/entry.txt",
247
"ftp://ftp.foo.com/dir1/dir1/entry.txt"),
248
new Entry("ftp://ftp.foo.com/dir1/jar.jar",
249
"/dir1/entry.txt",
250
"ftp://ftp.foo.com/dir1/entry.txt"),
251
new Entry("ftp://br:[email protected]/dir1/jar.jar",
252
"/dir1/entry.txt",
253
"ftp://br:[email protected]/dir1/entry.txt")
254
};
255
}
256
257