Fix loading of the native library for DNS resolutions on MacOS (#11260)

Motivation:

Cannot load the native library for DNS resolutions on MacOS.
The exception below is observed:

18:02:43.453 [Test worker] ERROR i.n.r.d.DnsServerAddressStreamProviders - Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS.
java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at io.netty.resolver.dns.DnsServerAddressStreamProviders.<clinit>(DnsServerAddressStreamProviders.java:64)
	at io.netty.resolver.dns.DnsNameResolverBuilder.<init>(DnsNameResolverBuilder.java:60)
	at reactor.netty.transport.NameResolverProvider.newNameResolverGroup(NameResolverProvider.java:432)
...
Caused by: java.lang.UnsatisfiedLinkError: io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.resolvers()[Lio/netty/resolver/dns/macos/DnsResolver;
	at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.resolvers(Native Method)
	at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.retrieveCurrentMappings(MacOSDnsServerAddressStreamProvider.java:127)
	at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.<init>(MacOSDnsServerAddressStreamProvider.java:123)

This is a regression made with #11239

Modification:

When checking for OS, an exception must be thrown when the OS is not MacOS

Result:

The native library for DNS resolutions on MacOS can be loaded
This commit is contained in:
Violeta Georgieva 2021-05-17 21:16:25 +03:00 committed by GitHub
parent a273c231fd
commit ccca3959fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,7 +82,7 @@ public final class MacOSDnsServerAddressStreamProvider implements DnsServerAddre
} }
private static void loadNativeLibrary() { private static void loadNativeLibrary() {
if (PlatformDependent.isOsx()) { if (!PlatformDependent.isOsx()) {
throw new IllegalStateException("Only supported on MacOS/OSX"); throw new IllegalStateException("Only supported on MacOS/OSX");
} }
String staticLibName = "netty_resolver_dns_native_macos"; String staticLibName = "netty_resolver_dns_native_macos";