0N/A/*
2362N/A * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4727547
0N/A * @summary SocksSocketImpl throws NullPointerException
0N/A * @build SocksServer
5671N/A * @run main SocksV4Test
0N/A */
0N/A
0N/Aimport java.net.*;
0N/A
0N/Apublic class SocksV4Test {
5670N/A
5670N/A // An unresolvable host
5670N/A static final String HOSTNAME = "doesnot.exist.invalid";
5670N/A
5669N/A public static void main(String[] args) throws Exception {
5670N/A // sanity before running the test
5670N/A assertUnresolvableHost(HOSTNAME);
5670N/A
5669N/A // Create a SOCKS V4 proxy
5669N/A SocksServer srvr = new SocksServer(0, true);
0N/A srvr.start();
5669N/A Proxy sp = new Proxy(Proxy.Type.SOCKS,
5669N/A new InetSocketAddress("localhost", srvr.getPort()));
0N/A // Let's create an unresolved address
5670N/A InetSocketAddress ad = new InetSocketAddress(HOSTNAME, 1234);
5669N/A try (Socket s = new Socket(sp)) {
5669N/A s.connect(ad, 10000);
0N/A } catch (UnknownHostException ex) {
0N/A // OK, that's what we expected
0N/A } catch (NullPointerException npe) {
0N/A // Not OK, this used to be the bug
0N/A throw new RuntimeException("Got a NUllPointerException");
0N/A } finally {
0N/A srvr.terminate();
0N/A }
0N/A }
5670N/A
5670N/A static void assertUnresolvableHost(String host) {
5670N/A InetAddress addr = null;
5670N/A try {
5670N/A addr = InetAddress.getByName(host);
5670N/A } catch (UnknownHostException x) {
5670N/A // OK, expected
5670N/A }
5670N/A if (addr != null)
5670N/A throw new RuntimeException("Test cannot run. resolvable address:" + addr);
5670N/A }
0N/A}