Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jvalkeal opened this issue Feb 8, 2022 · 5 comments
Open

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

jvalkeal opened this issue Feb 8, 2022 · 5 comments
Assignees
Labels
bug spring spring related issue

Comments

@jvalkeal
Copy link

jvalkeal commented Feb 8, 2022

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:

  • GraalVM version [latest, dev, '22.0.0.2']
  • JDK major version: [11/17]
  • OS: [Windows in GH Runners]
  • Architecture: [e.g.: AMD64]

More details

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

spring-attic/spring-native#1319
spring-projects/spring-framework#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.

@jvalkeal jvalkeal added the bug label Feb 8, 2022
@sdeleuze
Copy link
Collaborator

sdeleuze commented Feb 8, 2022

Please add the spring label to this issue.

@alina-yur alina-yur added the spring spring related issue label Feb 8, 2022
@fernando-valdez fernando-valdez self-assigned this Feb 14, 2022
@Saljack
Copy link

Saljack commented Mar 10, 2022

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

@Paullo612
Copy link

@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
Copy link

ShanGor commented Nov 26, 2022

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
Copy link

patpatpat123 commented Jan 4, 2023

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!!!

spring-projects/spring-data-redis#2480

eritpchy added a commit to eritpchy/aliyundrive-webdav that referenced this issue Apr 7, 2023
      	at sun.net.dns.ResolverConfigurationImpl.stringToList(ResolverConfigurationImpl.java:69)
oracle/graal#4304
wimdeblauwe added a commit to wimdeblauwe/ttcli that referenced this issue May 10, 2023
violetagg added a commit to reactor/reactor-netty that referenced this issue Nov 2, 2023
violetagg added a commit to reactor/reactor-netty that referenced this issue Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug spring spring related issue
Projects
None yet
Development

No branches or pull requests

8 participants