blob: db3b8389ef26f956d7868e3af11242bb44d3f775 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001-2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4321350
27 * @bug 4516522
28 * @summary Check that InetAddress.getByName() throws UHE with dotted
29 * IP address with octets out of range (Windows specific bug)
30 * or when bad IPv6 Litterals addresses are passed.
31 */
32import java.net.InetAddress;
33import java.net.UnknownHostException;
34
35public class BadDottedIPAddress {
36
37 public static void main(String args[]) throws Exception {
38
39 String host = "999.999.999.999";
40
41 boolean exc_thrown = false;
42 try {
43 InetAddress ia = InetAddress.getByName(host);
44 } catch (UnknownHostException e) {
45 exc_thrown = true;
46 }
47
48 if (!exc_thrown) {
49 throw new Exception("UnknownHostException was not thrown for: "
50 + host);
51 }
52
53 host = "[]";
54 exc_thrown = false;
55 try {
56 InetAddress ia = InetAddress.getByName(host);
57 } catch (UnknownHostException e) {
58 exc_thrown = true;
59 } catch (Exception e) {
60 }
61
62 if (!exc_thrown) {
63 throw new Exception("UnknownHostException was not thrown for: "
64 + host);
65 }
66
67 host = "[127.0.0.1]";
68 exc_thrown = false;
69 try {
70 InetAddress ia = InetAddress.getByName(host);
71 } catch (UnknownHostException e) {
72 exc_thrown = true;
73 } catch (Exception e) {
74 }
75
76 if (!exc_thrown) {
77 throw new Exception("UnknownHostException was not thrown for: "
78 + host);
79 }
80
81 host = "[localhost]";
82 exc_thrown = false;
83 try {
84 InetAddress ia = InetAddress.getByName(host);
85 } catch (UnknownHostException e) {
86 exc_thrown = true;
87 } catch (Exception e) {
88 }
89
90 if (!exc_thrown) {
91 throw new Exception("UnknownHostException was not thrown for: "
92 + host);
93 }
94 }
95}