Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/Socks/SocksV4Test.java
47427 views
1
/*
2
* Copyright (c) 2002, 2012, 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 4727547
27
* @summary SocksSocketImpl throws NullPointerException
28
* @build SocksServer
29
* @run main SocksV4Test
30
*/
31
32
import java.net.*;
33
34
public class SocksV4Test {
35
36
// An unresolvable host
37
static final String HOSTNAME = "doesnot.exist.invalid";
38
39
public static void main(String[] args) throws Exception {
40
// sanity before running the test
41
assertUnresolvableHost(HOSTNAME);
42
43
// Create a SOCKS V4 proxy
44
SocksServer srvr = new SocksServer(0, true);
45
srvr.start();
46
Proxy sp = new Proxy(Proxy.Type.SOCKS,
47
new InetSocketAddress("localhost", srvr.getPort()));
48
// Let's create an unresolved address
49
InetSocketAddress ad = new InetSocketAddress(HOSTNAME, 1234);
50
try (Socket s = new Socket(sp)) {
51
s.connect(ad, 10000);
52
} catch (UnknownHostException ex) {
53
// OK, that's what we expected
54
} catch (NullPointerException npe) {
55
// Not OK, this used to be the bug
56
throw new RuntimeException("Got a NUllPointerException");
57
} finally {
58
srvr.terminate();
59
}
60
}
61
62
static void assertUnresolvableHost(String host) {
63
InetAddress addr = null;
64
try {
65
addr = InetAddress.getByName(host);
66
} catch (UnknownHostException x) {
67
// OK, expected
68
}
69
if (addr != null)
70
throw new RuntimeException("Test cannot run. resolvable address:" + addr);
71
}
72
}
73
74