author | robm |
Tue, 25 Aug 2015 14:07:08 +0100 | |
changeset 32271 | d6cb1602f271 |
parent 30820 | 0d4717a011d3 |
child 36967 | d041d2e80712 |
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 |
|
32271
d6cb1602f271
8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents:
30820
diff
changeset
|
26 |
* @bug 4749938 8087190 |
2 | 27 |
* @summary Bug in the parsing IPv4 literal addresses |
30820 | 28 |
* @modules java.base/sun.net.spi.nameservice |
24124
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
29 |
* @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
|
30 |
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=dummy,oracle textToNumericFormat |
2 | 31 |
*/ |
32 |
||
24124
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
33 |
/** |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
34 |
* 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
|
35 |
* 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
|
36 |
* 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
|
37 |
* 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
|
38 |
* the exception. |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
39 |
*/ |
5f5f7f7a4328
8041621: java/net/Inet4Address/textToNumericFormat.java fails on Solaris and Mac
michaelm
parents:
24042
diff
changeset
|
40 |
|
2 | 41 |
import java.net.InetAddress; |
42 |
import java.net.UnknownHostException; |
|
43 |
import java.util.*; |
|
44 |
||
45 |
public class textToNumericFormat { |
|
46 |
||
47 |
public static void main(String[] args) throws UnknownHostException { |
|
24042
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
48 |
List<String> goodList = new ArrayList<>(); |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
49 |
List<String> badList = new ArrayList<>(); |
2 | 50 |
String goodAddrs[] = { |
51 |
"224.0.1.0", |
|
52 |
"238.255.255.255", |
|
24042
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
53 |
"239.255.255.255", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
54 |
"239.255.65535", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
55 |
"239.16777215", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
56 |
"4294967295" }; |
2 | 57 |
|
58 |
String badAddrs[] = { |
|
59 |
"238.255.255.2550", |
|
60 |
"256.255.255.255", |
|
61 |
"238.255.2550.255", |
|
62 |
"238.2550.255.255", |
|
24042
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
63 |
"2380.255.255.255", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
64 |
"239.255.65536", |
82290278c4af
8040747: Improve performance of IP address parsing
mduigou
parents:
5506
diff
changeset
|
65 |
"239.16777216", |
32271
d6cb1602f271
8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents:
30820
diff
changeset
|
66 |
"4294967296", |
d6cb1602f271
8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents:
30820
diff
changeset
|
67 |
".1.1.1", |
d6cb1602f271
8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents:
30820
diff
changeset
|
68 |
"1..1.1", |
d6cb1602f271
8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents:
30820
diff
changeset
|
69 |
"1.1.1.", |
d6cb1602f271
8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents:
30820
diff
changeset
|
70 |
"..." }; |
2 | 71 |
|
72 |
for (int i=0; i<goodAddrs.length; i++) { |
|
73 |
try { |
|
74 |
InetAddress ia = InetAddress.getByName(goodAddrs[i]); |
|
75 |
} catch (UnknownHostException e) { |
|
76 |
// shouldn't have come here |
|
77 |
goodList.add(goodAddrs[i]); |
|
78 |
} |
|
79 |
||
80 |
} |
|
81 |
||
82 |
for (int i=0; i<badAddrs.length; i++) { |
|
83 |
try { |
|
84 |
InetAddress ia = InetAddress.getByName(badAddrs[i]); |
|
85 |
// shouldn't have come here |
|
86 |
badList.add(badAddrs[i]); |
|
87 |
} catch (UnknownHostException e) { |
|
88 |
// ignore |
|
89 |
} |
|
90 |
||
91 |
} |
|
92 |
||
93 |
// if either goodList or badList is not empty, throw exception |
|
94 |
if (goodList.size() > 0 || badList.size() > 0) { |
|
95 |
throw new RuntimeException((goodList.size() > 0? |
|
96 |
("Good address not parsed: "+ goodList) |
|
97 |
: "") + |
|
98 |
(badList.size() > 0 ? |
|
99 |
("Bad Address parsed: "+ badList) |
|
100 |
: "")); |
|
101 |
} |
|
102 |
||
103 |
} |
|
104 |
||
105 |
} |