2 Replies Latest reply on Aug 28, 2008 1:54 PM by 843793

    InitialLdapContext IPV6 - NumberFormatException

           I have a sample program listed below for reference which makes
      use of an IPV6 address when setting up the environment for creating
      a ldapContext object through the use of initialLdapContext() call.

      When I compile and run this program I get "java.lang.NumberFormatException".
      Below is the code listing and sample run of the program. Also, the same
      program works fine without throwing any exceptions when I replace the IPV6
      address of the system with its corresponding IPV4 address.

      Could anyone please let me know as to why I get "NumberFormatException".

      PS: The sample program was built, compiled and run using JDK 1.5 and JRE 1.5
      and run on Windows-XP SP2 where IPV6 is configured and ping6 works for
      the same address (of a remote node).


      Code listing of the sample program:

      import java.util.*;
      import javax.naming.*;
      import javax.naming.directory.*;
      import javax.naming.ldap.*;
      import java.net.InetAddress;

      public class testipv6
      public static void main(String args[]) throws Exception

      int ldapVersion = 3;
      LdapContext ldapContext;
      Hashtable environment;
      int serverPort;
      int portNumber;
      InetAddress ipAddress = null;
      Control[] connCtls = null;

      String serverName;

      portNumber = 907;
      ipAddress = ipAddress.getByName("fe80::200:f8ff:fe25:6eb4");

      serverName = ipAddress.getHostName() + ":" + portNumber;

      // Initialize the environment for an LDAP directory

      environment = new Hashtable(11);
      environment.put(Context.PROVIDER_URL,"ldap://" + serverName);

      ldapContext = null;


      ldapContext = new InitialLdapContext(environment,connCtls);



      Compilation of the program:

      D:\>javac testipv6.java
      Note: testipv6.java uses unchecked or unsafe operations.
      Note: Recompile with -Xlint:unchecked for details.

      Sample Run of the program:

      D:\>java testipv6
      Exception in thread "main" java.lang.NumberFormatException: For input string: "0
      at java.lang.NumberFormatException.forInputString(Unknown Source)
      at java.lang.Integer.parseInt(Unknown Source)
      at java.lang.Integer.parseInt(Unknown Source)
      at com.sun.jndi.toolkit.url.Uri.parse(Unknown Source)
      at com.sun.jndi.toolkit.url.Uri.init(Unknown Source)
      at com.sun.jndi.ldap.LdapURL.<init>(Unknown Source)
      at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(Unknown Source)
      at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Unknown Source)
      at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(Unknown Source)
      at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(Unknown Source)
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.ldap.InitialLdapContext.<init>(Unknown Source)
      at testipv6.main(testipv6.java:46)

        • 1. Re: InitialLdapContext IPV6 - NumberFormatException

          I assume, that the IPv6 URL you're passing looks like
          In this case, parsing the URL is difficult: what is part of the IP address? What is the port number? For that reason, the URL format is modified for IPv6 and adds brackets around the address:
          See RFC2732, e.g.
          I have not tested it, but I assume that this is the problem.
          • 2. Re: InitialLdapContext IPV6 - NumberFormatException
            I think this is a bug: