Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5054615

Generification conflict: Properties vs. javax.naming.InitialContext

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2
    • 5.0
    • 5.0
    • core-libs
    • b59
    • generic
    • solaris_8

    Description

      There is a conflict in the API generification.

      java.util.Properties has been generified as Map<Object,Object> because some existing clients use non-strings in properties. This is unfortunate, but we really don't want to break existing clients.

      javax.naming.InitialContext and javax.naming.directory.InitialDirContext work with properties objects explicitly. However, they describe properties using the type Hashtable<String,?> (in the constructors) and Hashtable<String,Object> (in InitialContext.myProps) rather than Properties.

      The enclosed application demonstrates that any client that currently uses a
      Properties object to initialize a javax.naming.InitialContext will be broken by the current generification.

      import java.util.*;
      import javax.naming.*;
      import javax.naming.directory.*;

      public class LdapTest {
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) throws Exception {
              DirContext rootCtx, jndiCtx, jndiObject;
              Properties jndiProperties;
              String dsServiceName;

              if(args.length != 3) {
                  System.out.println("Usage: LdapTest Server Account Password");
                  System.exit(0);
              }

              jndiProperties = new java.util.Properties();
              jndiProperties.put("java.naming.security.authentication", "simple");
              jndiProperties.put("java.naming.provider.url", "ldap://" + args[0] + "/");
              jndiProperties.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFac\tory");
              jndiProperties.put("java.naming.security.principal", args[1]);
              jndiProperties.put("java.naming.security.credentials", args[2]);

              rootCtx = new InitialDirContext(jndiProperties);
              dsServiceName = (String)rootCtx.getAttributes("").get("dsServiceName").get();

              System.out.println(dsServiceName);
          }

      }

      Attachments

        Issue Links

          Activity

            People

              mr Mark Reinhold
              gafter Neal Gafter
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: