Path: blob/master/test/jdk/java/net/ProxySelector/NullArguments.java
41152 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 493796225* @summary ProxySelector.connectFailed and .select never throw IllegalArgumentException26*/27import java.net.*;28import java.util.List;29import java.io.IOException;3031public class NullArguments {32public static void main(String[] args) {33ProxySelector ps = ProxySelector.getDefault();34List p = null;35boolean ok = false;36if (ps != null) {37try {38p = ps.select(null);39} catch (IllegalArgumentException iae) {40System.out.println("OK");41ok = true;42}43if (!ok)44throw new RuntimeException("Expected IllegalArgumentException!");45URI uri = null;46try {47uri = new URI("http://java.sun.com");48} catch (java.net.URISyntaxException use) {49// can't happen50}51SocketAddress sa = new InetSocketAddress("localhost", 80);52IOException ioe = new IOException("dummy IOE");53ok = false;54try {55ps.connectFailed(uri, sa, null);56} catch (IllegalArgumentException iae) {57System.out.println("OK");58ok = true;59}60if (!ok)61throw new RuntimeException("Expected IllegalArgumentException!");62ok = false;63try {64ps.connectFailed(uri, null, ioe);65} catch (IllegalArgumentException iae) {66System.out.println("OK");67ok = true;68}69if (!ok)70throw new RuntimeException("Expected IllegalArgumentException!");71ok = false;72try {73ps.connectFailed(null, sa, ioe);74} catch (IllegalArgumentException iae) {75System.out.println("OK");76ok = true;77}78if (!ok)79throw new RuntimeException("Expected IllegalArgumentException!");80}81}82}838485