Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/FixingJavadocs/JavaxURLNulls.java
41153 views
1
/*
2
* Copyright (c) 2001, 2011, 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 4387882
27
* @summary Need to revisit the javadocs for JSSE, especially the
28
* promoted classes
29
* @author Brad Wetmore
30
*/
31
32
import java.net.*;
33
import java.io.*;
34
import javax.net.ssl.*;
35
36
37
/*
38
* Tests that the javax null argument changes made it in ok.
39
*/
40
41
public class JavaxURLNulls {
42
43
public static void main(String[] args) throws Exception {
44
45
HostnameVerifier reservedHV =
46
HttpsURLConnection.getDefaultHostnameVerifier();
47
try {
48
/**
49
* This test does not establish any connection to the specified
50
* URL, hence a dummy URL is used.
51
*/
52
URL foobar = new URL("https://example.com/");
53
54
HttpsURLConnection urlc =
55
(HttpsURLConnection) foobar.openConnection();
56
57
try {
58
urlc.getCipherSuite();
59
} catch (IllegalStateException e) {
60
System.out.print("Caught proper exception: ");
61
System.out.println(e.getMessage());
62
}
63
64
try {
65
urlc.getLocalCertificates();
66
} catch (IllegalStateException e) {
67
System.out.print("Caught proper exception: ");
68
System.out.println(e.getMessage());
69
}
70
71
try {
72
urlc.getServerCertificates();
73
} catch (IllegalStateException e) {
74
System.out.print("Caught proper exception: ");
75
System.out.println(e.getMessage());
76
}
77
78
try {
79
urlc.setDefaultHostnameVerifier(null);
80
} catch (IllegalArgumentException e) {
81
System.out.print("Caught proper exception: ");
82
System.out.println(e.getMessage());
83
}
84
85
try {
86
urlc.setHostnameVerifier(null);
87
} catch (IllegalArgumentException e) {
88
System.out.print("Caught proper exception: ");
89
System.out.println(e.getMessage());
90
}
91
92
try {
93
urlc.setDefaultSSLSocketFactory(null);
94
} catch (IllegalArgumentException e) {
95
System.out.print("Caught proper exception: ");
96
System.out.println(e.getMessage());
97
}
98
99
try {
100
urlc.setSSLSocketFactory(null);
101
} catch (IllegalArgumentException e) {
102
System.out.print("Caught proper exception: ");
103
System.out.println(e.getMessage());
104
}
105
System.out.println("TESTS PASSED");
106
} finally {
107
HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
108
}
109
}
110
}
111
112