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

IllegalAccessException for com.sun.jndi.dns.DnsContextFactory #119

Open
creckord opened this issue Nov 28, 2024 · 1 comment
Open

IllegalAccessException for com.sun.jndi.dns.DnsContextFactory #119

creckord opened this issue Nov 28, 2024 · 1 comment
Labels

Comments

@creckord
Copy link

I'm not quite sure where to place this bug - here, with Maven, with Netty, or with the affected Maven plugin. So I'm going to start here...

I am using the apicurio-registry-maven-plugin in my Maven build with Java 21.

Under the hood, this uses Netty. Under Windows, Netty uses JNDI to get the system DNS servers, essentially doing this:

        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
        env.put("java.naming.provider.url", "dns://");

        DirContext ctx = new InitialDirContext(env);
        String dnsUrls = (String) ctx.getEnvironment().get("java.naming.provider.url");

When this code runs in a Maven plugin, this fails with

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.dns.DnsContextFactory [Root exception is java.lang.IllegalAccessException: class javax.naming.spi.NamingManager (in module java.naming) cannot access class com.sun.jndi.dns.DnsContextFactory (in module jdk.naming.dns) because module jdk.naming.dns does not export com.sun.jndi.dns to module java.naming]

When I run the same code directly as a Java application, with the same JVM options, classpath etc., it works fine. I suspect that this has something to do with the plexus-classworlds classloader system, but I'm at a loss what, why and how.

System:
Windows 11
OpenJDK 21.0.5 (Eclipse Temurin-21.0.5+11)
Maven 3.9.9
apicurio-registry-maven-plugin 3.0.4
Netty 4.1.111

@creckord
Copy link
Author

Interesting enough, if I run Maven with MAVEN_OPTS="--add-opens jdk.naming.dns/com.sun.jndi.dns=java.naming", it works, even though that should not be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants