author | michaelm |
Mon, 28 Apr 2014 13:49:49 +0100 | |
changeset 24124 | 5f5f7f7a4328 |
parent 24042 | 82290278c4af |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4749938 |
|
27 |
* @summary Bug in the parsing IPv4 literal addresses |
|
24124
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
28 |
* @compile -XDignore.symbol.file=true DummyNameService.java DummyNameServiceDescriptor.java |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
29 |
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=dummy,oracle textToNumericFormat |
2 | 30 |
*/ |
31 |
||
24124
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
32 |
/** |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
33 |
* We use a dummy name service which throws UHE any time it is called. |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
34 |
* We do this because the "good" tests here should parse correctly |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
35 |
* without needing to call the name service, and the bad tests will |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
36 |
* not parse and then invoke the name service, where we expect |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
37 |
* the exception. |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
38 |
*/ |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
39 |
|
2 | 40 |
import java.net.InetAddress; |
41 |
import java.net.UnknownHostException; |
|
42 |
import java.util.*; |
|
43 |
||
44 |
public class textToNumericFormat { |
|
45 |
||
46 |
public static void main(String[] args) throws UnknownHostException { |
|
24042
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
47 |
List<String> goodList = new ArrayList<>(); |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
48 |
List<String> badList = new ArrayList<>(); |
2 | 49 |
String goodAddrs[] = { |
50 |
"224.0.1.0", |
|
51 |
"238.255.255.255", |
|
24042
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
52 |
"239.255.255.255", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
53 |
"239.255.65535", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
54 |
"239.16777215", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
55 |
"4294967295" }; |
2 | 56 |
|
57 |
String badAddrs[] = { |
|
58 |
"238.255.255.2550", |
|
59 |
"256.255.255.255", |
|
60 |
"238.255.2550.255", |
|
61 |
"238.2550.255.255", |
|
24042
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
62 |
"2380.255.255.255", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
63 |
"239.255.65536", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
64 |
"239.16777216", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
65 |
"4294967296" }; |
2 | 66 |
|
67 |
for (int i=0; i<goodAddrs.length; i++) { |
|
68 |
try { |
|
69 |
InetAddress ia = InetAddress.getByName(goodAddrs[i]); |
|
70 |
} catch (UnknownHostException e) { |
|
71 |
// shouldn't have come here |
|
72 |
goodList.add(goodAddrs[i]); |
|
73 |
} |
|
74 |
||
75 |
} |
|
76 |
||
77 |
for (int i=0; i<badAddrs.length; i++) { |
|
78 |
try { |
|
79 |
InetAddress ia = InetAddress.getByName(badAddrs[i]); |
|
80 |
// shouldn't have come here |
|
81 |
badList.add(badAddrs[i]); |
|
82 |
} catch (UnknownHostException e) { |
|
83 |
// ignore |
|
84 |
} |
|
85 |
||
86 |
} |
|
87 |
||
88 |
// if either goodList or badList is not empty, throw exception |
|
89 |
if (goodList.size() > 0 || badList.size() > 0) { |
|
90 |
throw new RuntimeException((goodList.size() > 0? |
|
91 |
("Good address not parsed: "+ goodList) |
|
92 |
: "") + |
|
93 |
(badList.size() > 0 ? |
|
94 |
("Bad Address parsed: "+ badList) |
|
95 |
: "")); |
|
96 |
} |
|
97 |
||
98 |
} |
|
99 |
||
100 |
} |