oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.34k stars 1.63k forks source link

javax.naming.directory.InitialDirContext fails on windows #4304

Open jvalkeal opened 2 years ago

jvalkeal commented 2 years ago

Describe the issue

Essentially on windows image you will get NPE from:

java.lang.NullPointerException
    at sun.net.dns.ResolverConfigurationImpl.stringToList(ResolverConfigurationImpl.java:69)
    at sun.net.dns.ResolverConfigurationImpl.loadConfig(ResolverConfigurationImpl.java:136)
    at sun.net.dns.ResolverConfigurationImpl.nameservers(ResolverConfigurationImpl.java:159)
    at com.sun.jndi.dns.DnsContextFactory.serversForUrls(DnsContextFactory.java:149)
    at com.sun.jndi.dns.DnsContextFactory.getContext(DnsContextFactory.java:81)
    at com.sun.jndi.dns.DnsContextFactory.urlToContext(DnsContextFactory.java:120)
    at com.sun.jndi.dns.DnsContextFactory.getInitialContext(DnsContextFactory.java:64)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:732)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
    at javax.naming.InitialContext.init(InitialContext.java:236)
    at javax.naming.InitialContext.<init>(InitialContext.java:208)
    at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:130)

Steps to reproduce the issue

Test code and GH Actions runs can be found from https://github.com/jvalkeal/win-netty-issue. There doesn't seem to be any issues on macos/linux, just when running native on windows. Matrix build shows that java Test runs ok but test.exe doesn't.

Describe GraalVM and your environment:

More details

This was originally reported and discussed as a netty issue as it looks to initiate call to this stack.

https://github.com/spring-projects-experimental/spring-native/issues/1319 https://github.com/spring-projects/spring-framework/issues/27749

However looks like for some reason https://github.com/openjdk/jdk/blob/a9a271179d2a7952154b7509a999b100cc98b13c/src/java.base/windows/classes/sun/net/dns/ResolverConfigurationImpl.java#L101 doesn't initialize class fields via native call, thus the NPE. Or at least that's where my debugging skills stopped.

sdeleuze commented 2 years ago

Please add the spring label to this issue.

Saljack commented 2 years ago

Hi I am also affected with this issue. Is there any workaround?

Paullo612 commented 2 years ago

@Saljack, you can use following jni-config.json

[
  {
    "name":"sun.net.dns.ResolverConfigurationImpl",
    "fields":[
      {"name":"os_searchlist"},
      {"name":"os_nameservers"}
    ]
  }
]

in conjunction with --initialize-at-run-time=sun.net.dns.ResolverConfigurationImpl as workaround.

ShanGor commented 1 year ago

Thanks for your suggestion, it is really helpful for resolving my problem. Let me paste my error message to help the search engine to locate this page [ WARN] (Thread-0) throwIfFatal detected a jvm fatal exception, which is thrown and logged below: - java.lang.ExceptionInInitializerError java.lang.ExceptionInInitializerError at io.netty.resolver.dns.DnsServerAddressStreamProviders$DefaultProviderHolder$1.provider(DnsServerAddressStreamProviders.java:142) at io.netty.resolver.dns.DnsServerAddressStreamProviders$DefaultProviderHolder$1.<init>(DnsServerAddressStreamProviders.java:122) at io.netty.resolver.dns.DnsServerAddressStreamProviders$DefaultProviderHolder.<clinit>(DnsServerAddressStreamProviders.java:120) at io.netty.resolver.dns.DnsServerAddressStreamProviders.unixDefault(DnsServerAddressStreamProviders.java:109) at io.netty.resolver.dns.DnsServerAddressStreamProviders.platformDefault(DnsServerAddressStreamProviders.java:105) at io.netty.resolver.dns.DnsNameResolverBuilder.<init>(DnsNameResolverBuilder.java:60) at reactor.netty.transport.NameResolverProvider.newNameResolverGroup(NameResolverProvider.java:479) at reactor.netty.tcp.TcpResources.getOrCreateDefaultResolver(TcpResources.java:315) at reactor.netty.http.HttpResources.getOrCreateDefaultResolver(HttpResources.java:162) at reactor.netty.http.client.HttpClientConfig.defaultAddressResolverGroup(HttpClientConfig.java:395) at reactor.netty.transport.ClientTransportConfig.resolverInternal(ClientTransportConfig.java:225) at reactor.netty.http.client.HttpClientConfig.resolverInternal(HttpClientConfig.java:449) at reactor.netty.http.client.HttpClientConnect$MonoHttpConnect.lambda$subscribe$0(HttpClientConnect.java:265) at reactor.core.publisher.MonoCreate.subscribe(MonoCreate.java:58) at reactor.core.publisher.FluxRetryWhen.subscribe(FluxRetryWhen.java:77) at reactor.core.publisher.MonoRetryWhen.subscribeOrReturn(MonoRetryWhen.java:46) at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57) at reactor.netty.http.client.HttpClientConnect$MonoHttpConnect.subscribe(HttpClientConnect.java:272) at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) at reactor.core.publisher.MonoDeferContextual.subscribe(MonoDeferContextual.java:55) at reactor.core.publisher.Mono.subscribe(Mono.java:4444) at reactor.core.publisher.Mono.subscribeWith(Mono.java:4510) at reactor.core.publisher.Mono.subscribe(Mono.java:4272) at cn.gzten.kay.KayWithWebClient.issueAnHttpRequest(KayWithWebClient.java:145) at java.base@19.0.1/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577) at java.base@19.0.1/java.util.concurrent.FutureTask.run(FutureTask.java:317) at java.base@19.0.1/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) at java.base@19.0.1/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) at java.base@19.0.1/java.lang.Thread.run(Thread.java:1589) at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775) at org.graalvm.nativeimage.builder/com.oracle.svm.core.windows.WindowsPlatformThreads.osThreadStartRoutine(WindowsPlatformThreads.java:178) Caused by: java.lang.NullPointerException at java.base@19.0.1/sun.net.dns.ResolverConfigurationImpl.stringToList(ResolverConfigurationImpl.java:71) at java.base@19.0.1/sun.net.dns.ResolverConfigurationImpl.loadConfig(ResolverConfigurationImpl.java:138) at java.base@19.0.1/sun.net.dns.ResolverConfigurationImpl.nameservers(ResolverConfigurationImpl.java:161) at jdk.naming.dns@19.0.1/com.sun.jndi.dns.DnsContextFactory.serversForUrls(DnsContextFactory.java:149) at jdk.naming.dns@19.0.1/com.sun.jndi.dns.DnsContextFactory.getContext(DnsContextFactory.java:81) at jdk.naming.dns@19.0.1/com.sun.jndi.dns.DnsContextFactory.urlToContext(DnsContextFactory.java:120) at jdk.naming.dns@19.0.1/com.sun.jndi.dns.DnsContextFactory.getInitialContext(DnsContextFactory.java:64) at java.naming@19.0.1/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:732) at java.naming@19.0.1/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305) at java.naming@19.0.1/javax.naming.InitialContext.init(InitialContext.java:236) at java.naming@19.0.1/javax.naming.InitialContext.<init>(InitialContext.java:208) at java.naming@19.0.1/javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:130) at io.netty.resolver.dns.DirContextUtils.addNameServers(DirContextUtils.java:49) at io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider.<clinit>(DefaultDnsServerAddressStreamProvider.java:53) ... 31 more

patpatpat123 commented 1 year ago

Hello Team,

I am also encountering this issue. The suggested workaround is working, many thanks. With that said, would it be possible to have a permanent fix instead of the workaround please? Maybe could you provide a Registrar like solution?

Thank you, happy new year!!!

https://github.com/spring-projects/spring-data-redis/issues/2480