author | mikael |
Fri, 04 Dec 2015 15:08:49 -0800 | |
changeset 35090 | 1f5b6aa795d0 |
parent 16748 | ed60b6527f64 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
16748 | 2 |
* Copyright (c) 2001, 2013, 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 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 4485208 |
|
27 |
* @summary file: and ftp: URL handlers need to throw NPE in setRequestProperty |
|
28 |
*/ |
|
29 |
||
30 |
import java.net.*; |
|
15528
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
31 |
import java.util.ArrayList; |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
32 |
import java.util.List; |
2 | 33 |
|
34 |
public class RequestProperties { |
|
15528
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
35 |
static int failed; |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
36 |
|
2 | 37 |
public static void main (String args[]) throws Exception { |
15528
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
38 |
List<String> urls = new ArrayList<>(); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
39 |
urls.add("http://foo.com/bar/"); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
40 |
urls.add("jar:http://foo.com/bar.html!/foo/bar"); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
41 |
urls.add("file:/etc/passwd"); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
42 |
if (hasFtp()) |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
43 |
urls.add("ftp://foo:bar@foobar.com/etc/passwd"); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
44 |
|
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
45 |
for (String urlStr : urls) |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
46 |
test(new URL(urlStr)); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
47 |
|
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
48 |
if (failed != 0) |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
49 |
throw new RuntimeException(failed + " errors") ; |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
50 |
} |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
51 |
|
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
52 |
static void test(URL url) throws Exception { |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
53 |
URLConnection urlc = url.openConnection(); |
2 | 54 |
try { |
15528
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
55 |
urlc.setRequestProperty(null, null); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
56 |
System.out.println(url.getProtocol() |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
57 |
+ ": setRequestProperty(null,) did not throw NPE"); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
58 |
failed++; |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
59 |
} catch (NullPointerException e) { /* Expected */ } |
2 | 60 |
try { |
15528
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
61 |
urlc.addRequestProperty(null, null); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
62 |
System.out.println(url.getProtocol() |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
63 |
+ ": addRequestProperty(null,) did not throw NPE"); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
64 |
failed++; |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
65 |
} catch (NullPointerException e) { /* Expected */ } |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
66 |
|
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
67 |
if (urlc.getRequestProperty(null) != null) { |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
68 |
System.out.println(url.getProtocol() |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
69 |
+ ": getRequestProperty(null,) did not return null"); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
70 |
failed++; |
2 | 71 |
} |
15528
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
72 |
} |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
73 |
|
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
74 |
private static boolean hasFtp() { |
2 | 75 |
try { |
15528
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
76 |
return new java.net.URL("ftp://") != null; |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
77 |
} catch (java.net.MalformedURLException x) { |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
78 |
System.out.println("FTP not supported by this runtime."); |
18f0bac88177
8007322: untangle ftp protocol from general networking URL tests
chegar
parents:
5506
diff
changeset
|
79 |
return false; |
2 | 80 |
} |
81 |
} |
|
82 |
} |