Path: blob/master/test/jdk/java/net/InetAddress/BadDottedIPAddress.java
41149 views
/*1* Copyright (c) 2001, 2002, 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/*24* @test25* @bug 432135026* @bug 451652227* @summary Check that InetAddress.getByName() throws UHE with dotted28* IP address with octets out of range (Windows specific bug)29* or when bad IPv6 Litterals addresses are passed.30*/31import java.net.InetAddress;32import java.net.UnknownHostException;3334public class BadDottedIPAddress {3536public static void main(String args[]) throws Exception {3738String host = "999.999.999.999";3940boolean exc_thrown = false;41try {42InetAddress ia = InetAddress.getByName(host);43} catch (UnknownHostException e) {44exc_thrown = true;45}4647if (!exc_thrown) {48throw new Exception("UnknownHostException was not thrown for: "49+ host);50}5152host = "[]";53exc_thrown = false;54try {55InetAddress ia = InetAddress.getByName(host);56} catch (UnknownHostException e) {57exc_thrown = true;58} catch (Exception e) {59}6061if (!exc_thrown) {62throw new Exception("UnknownHostException was not thrown for: "63+ host);64}6566host = "[127.0.0.1]";67exc_thrown = false;68try {69InetAddress ia = InetAddress.getByName(host);70} catch (UnknownHostException e) {71exc_thrown = true;72} catch (Exception e) {73}7475if (!exc_thrown) {76throw new Exception("UnknownHostException was not thrown for: "77+ host);78}7980host = "[localhost]";81exc_thrown = false;82try {83InetAddress ia = InetAddress.getByName(host);84} catch (UnknownHostException e) {85exc_thrown = true;86} catch (Exception e) {87}8889if (!exc_thrown) {90throw new Exception("UnknownHostException was not thrown for: "91+ host);92}93}94}959697