Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/jndi/dns/IPv6NameserverPlatformParsingTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 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
import java.lang.reflect.Field;
25
import java.util.Hashtable;
26
27
import javax.naming.Context;
28
import javax.naming.NamingException;
29
import javax.naming.spi.NamingManager;
30
31
import com.sun.jndi.dns.DnsContext;
32
33
/**
34
* @bug 6991580
35
* @summary IPv6 Nameservers in resolv.conf throws NumberFormatException
36
*
37
* @author Severin Gehwolf
38
*/
39
40
public class IPv6NameserverPlatformParsingTest {
41
42
private static boolean foundIPv6 = false;
43
44
public static void main(String[] args) {
45
Hashtable<String, String> env = new Hashtable<>();
46
env.put(Context.INITIAL_CONTEXT_FACTORY, com.sun.jndi.dns.DnsContextFactory.class.getName());
47
48
String[] servers;
49
try {
50
Context ctx = NamingManager.getInitialContext(env);
51
if (!com.sun.jndi.dns.DnsContextFactory.platformServersAvailable()) {
52
throw new RuntimeException("FAIL: no platform servers available, test does not make sense");
53
}
54
DnsContext context = (DnsContext)ctx;
55
servers = getServersFromContext(context);
56
} catch (NamingException e) {
57
throw new RuntimeException(e);
58
}
59
for (String server: servers) {
60
System.out.println("DEBUG: 'nameserver = " + server + "'");
61
if (server.indexOf(':') >= 0 && server.indexOf('.') < 0) {
62
System.out.println("DEBUG: ==> Found IPv6 address in servers list: " + server);
63
foundIPv6 = true;
64
}
65
}
66
try {
67
new com.sun.jndi.dns.DnsClient(servers, 100, 1);
68
} catch (NumberFormatException e) {
69
throw new RuntimeException("FAIL: Tried to parse non-[]-encapsulated IPv6 address.", e);
70
} catch (Exception e) {
71
throw new RuntimeException("ERROR: Something unexpected happened.");
72
}
73
if (!foundIPv6) {
74
// This is a manual test, since it requires changing /etc/resolv.conf on Linux/Unix
75
// platforms. See comment as to how to run this test.
76
throw new RuntimeException("ERROR: No IPv6 address returned from platform.");
77
}
78
System.out.println("PASS: Found IPv6 address and DnsClient parsed it correctly.");
79
}
80
81
private static String[] getServersFromContext(DnsContext context) {
82
try {
83
Field serversField = DnsContext.class.getDeclaredField("servers");
84
serversField.setAccessible(true);
85
return (String[])serversField.get(context);
86
} catch (Exception e) {
87
throw new RuntimeException(e);
88
}
89
}
90
91
}
92
93