Description
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