Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/Inet4Address/textToNumericFormat.java
47178 views
1
/*
2
* Copyright (c) 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
24
/*
25
* @test
26
* @bug 4749938 8087190
27
* @summary Bug in the parsing IPv4 literal addresses
28
* @compile -XDignore.symbol.file=true DummyNameService.java DummyNameServiceDescriptor.java
29
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=dummy,oracle textToNumericFormat
30
*/
31
32
/**
33
* We use a dummy name service which throws UHE any time it is called.
34
* We do this because the "good" tests here should parse correctly
35
* without needing to call the name service, and the bad tests will
36
* not parse and then invoke the name service, where we expect
37
* the exception.
38
*/
39
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 {
47
List<String> goodList = new ArrayList<>();
48
List<String> badList = new ArrayList<>();
49
String goodAddrs[] = {
50
"224.0.1.0",
51
"238.255.255.255",
52
"239.255.255.255",
53
"239.255.65535",
54
"239.16777215",
55
"4294967295" };
56
57
String badAddrs[] = {
58
"238.255.255.2550",
59
"256.255.255.255",
60
"238.255.2550.255",
61
"238.2550.255.255",
62
"2380.255.255.255",
63
"239.255.65536",
64
"239.16777216",
65
"4294967296",
66
".1.1.1",
67
"1..1.1",
68
"1.1.1.",
69
"..." };
70
71
for (int i=0; i<goodAddrs.length; i++) {
72
try {
73
InetAddress ia = InetAddress.getByName(goodAddrs[i]);
74
} catch (UnknownHostException e) {
75
// shouldn't have come here
76
goodList.add(goodAddrs[i]);
77
}
78
79
}
80
81
for (int i=0; i<badAddrs.length; i++) {
82
try {
83
InetAddress ia = InetAddress.getByName(badAddrs[i]);
84
// shouldn't have come here
85
badList.add(badAddrs[i]);
86
} catch (UnknownHostException e) {
87
// ignore
88
}
89
90
}
91
92
// if either goodList or badList is not empty, throw exception
93
if (goodList.size() > 0 || badList.size() > 0) {
94
throw new RuntimeException((goodList.size() > 0?
95
("Good address not parsed: "+ goodList)
96
: "") +
97
(badList.size() > 0 ?
98
("Bad Address parsed: "+ badList)
99
: ""));
100
}
101
102
}
103
104
}
105
106