Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-19339

Failed to instantiate InitialContextFactory com.sun.jndi.dns.DnsContextFactory

XMLWordPrintable

    • Hide

      Following code will throw NamingException from InitialDirContext constructor:

      import java.util.Hashtable;
      import javax.naming.directory.InitialDirContext;
      import javax.naming.directory.DirContext;

      Hashtable env = new Hashtable();
      env.put("java.naming.provider.url", "dns://10.11.12.13");
      DirContext context = new InitialDirContext(env);

      Show
      Following code will throw NamingException from InitialDirContext constructor: import java.util.Hashtable; import javax.naming.directory.InitialDirContext; import javax.naming.directory.DirContext; Hashtable env = new Hashtable(); env.put("java.naming.provider.url", "dns://10.11.12.13"); DirContext context = new InitialDirContext(env);
    • Hide

      Adding a jboss-deployment-structure.xml works around the issue:

      standalone$ cat deployments/jespa.war/WEB-INF/jboss-deployment-structure.xml 
      <?xml version="1.0" encoding="UTF-8"?>

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
          <deployment>
              <dependencies>
                  <system export="true">
                      <paths>
                          <path name="com/sun/jndi/dns"/>
                      </paths>
                  </system>
              </dependencies>
          </deployment>
      </jboss-deployment-structure>

      Show
      Adding a jboss-deployment-structure.xml works around the issue: standalone$ cat deployments/jespa.war/WEB-INF/jboss-deployment-structure.xml  <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">     <deployment>         <dependencies>             <system export="true">                 <paths>                     <path name="com/sun/jndi/dns"/>                 </paths>             </system>         </dependencies>     </deployment> </jboss-deployment-structure>
    • ---
    • ---

      WF 30.0.1 and allegedly 29 or later but not 28 fails with:

      javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory com.sun.jndi.dns.DnsContextFactory from classloader ModuleClassLoader for Module "deployment.jespa.war" from Service Module Loader [Root exception is java.lang.ClassNotFoundException: com.sun.jndi.dns.DnsContextFactory from [Module "deployment.jespa.war" from Service Module Loader]
          at org.jboss.as.naming@31.0.1.Final//org.jboss.as.naming.InitialContext.getDefaultInitCtx(InitialContext.java:103)
          at org.jboss.as.naming@31.0.1.Final//org.jboss.as.naming.InitialContext.init(InitialContext.java:84)
          at java.naming/javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:154)
          at org.jboss.as.naming@31.0.1.Final//org.jboss.as.naming.InitialContext.<init>(InitialContext.java:74)
          at org.jboss.as.naming@31.0.1.Final//org.jboss.as.naming.InitialContextFactory.getInitialContext(InitialContextFactory.java:26)
          at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:730)
          at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
          at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
          at java.naming/javax.naming.InitialContext.<init>(InitialContext.java:208)
          at java.naming/javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:101)
          at deployment.jespa.war//jespa.dns.Dns.getRecordsByName0(Dns.java:207)
          at deployment.jespa.war//jespa.dns.Dns.getRecordsByName(Dns.java:363)
      ...

      when trying to instantiate InitialDirContext with a dns:// java.naming.provider.url.

      Presumably this is not intentional behavior because the default JAVA_OPTS has --add-exports=jdk.naming.dns/com.sun.jndi.dns=ALL-UNNAMED and because being able to do DNS manually is an important use case (such as for doing SRV lookups of Windows domain controllers in corp environments).
      Note that com.sun.jndi.ldap classes load fine.

            ropalka Richard Opalka
            miallen Michael B. Allen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: