Do not try to retrieve domain search list via reflection hack on windows when using Java9 and later (#9511)

Motivation:

We currently try to access the the domain search list via reflection on windows which will print a illegal access warning when using Java9 and later.

Modifications:

Add a guard against the used java version.

Result:

Fixes https://github.com/netty/netty/issues/9500.
This commit is contained in:
Norman Maurer 2019-08-28 08:08:01 +02:00 committed by GitHub
parent a89cde9475
commit 68673b652e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -177,14 +177,19 @@ public class DnsNameResolver extends InetNameResolver {
@SuppressWarnings("unchecked")
private static List<String> getSearchDomainsHack() throws Exception {
// This code on Java 9+ yields a warning about illegal reflective access that will be denied in
// a future release. There doesn't seem to be a better way to get search domains for Windows yet.
Class<?> configClass = Class.forName("sun.net.dns.ResolverConfiguration");
Method open = configClass.getMethod("open");
Method nameservers = configClass.getMethod("searchlist");
Object instance = open.invoke(null);
// Only try if not using Java9 and later
// See https://github.com/netty/netty/issues/9500
if (PlatformDependent.javaVersion() < 9) {
// This code on Java 9+ yields a warning about illegal reflective access that will be denied in
// a future release. There doesn't seem to be a better way to get search domains for Windows yet.
Class<?> configClass = Class.forName("sun.net.dns.ResolverConfiguration");
Method open = configClass.getMethod("open");
Method nameservers = configClass.getMethod("searchlist");
Object instance = open.invoke(null);
return (List<String>) nameservers.invoke(instance);
return (List<String>) nameservers.invoke(instance);
}
return Collections.emptyList();
}
private static final DatagramDnsResponseDecoder DATAGRAM_DECODER = new DatagramDnsResponseDecoder() {