1 /* 2 * Copyright (c) 2001, 2002, 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 package test.java.net.InetAddress; 24 25 /* 26 * @test 27 * @bug 4321350 28 * @bug 4516522 29 * @summary Check that InetAddress.getByName() throws UHE with dotted 30 * IP address with octets out of range (Windows specific bug) 31 * or when bad IPv6 Litterals addresses are passed. 32 */ 33 import java.net.InetAddress; 34 import java.net.UnknownHostException; 35 36 import org.testng.annotations.Test; 37 import org.testng.Assert; 38 39 public class BadDottedIPAddress { 40 41 @Test testBadDotted()42 public void testBadDotted() throws Exception { 43 44 String host = "999.999.999.999"; 45 46 try { 47 InetAddress ia = InetAddress.getByName(host); 48 Assert.fail(); 49 } catch (UnknownHostException e) { 50 } 51 52 53 host = "[]"; 54 try { 55 InetAddress ia = InetAddress.getByName(host); 56 Assert.fail(); 57 } catch (UnknownHostException e) { 58 } catch (Exception e) { 59 Assert.fail(); 60 } 61 62 63 host = "[127.0.0.1]"; 64 try { 65 InetAddress ia = InetAddress.getByName(host); 66 Assert.fail(); 67 } catch (UnknownHostException e) { 68 } catch (Exception e) { 69 Assert.fail(); 70 } 71 72 host = "[localhost]"; 73 try { 74 InetAddress ia = InetAddress.getByName(host); 75 Assert.fail(); 76 } catch (UnknownHostException e) { 77 } catch (Exception e) { 78 Assert.fail(); 79 } 80 } 81 }