Skip to content

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

@creckord

Description

@creckord

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

Activity

creckord

creckord commented on Nov 28, 2024

@creckord
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @creckord@slachiewicz

        Issue actions

          IllegalAccessException for com.sun.jndi.dns.DnsContextFactory · Issue #119 · codehaus-plexus/plexus-classworlds