JDK-5054615 : Generification conflict: Properties vs. javax.naming.InitialContext
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2004-05-28
  • Updated: 2017-05-16
  • Resolved: 2004-07-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b59Fixed
Related Reports
Relates :  
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);
    }

}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b59 tiger-rc
03-08-2004

EVALUATION The best fix for this bug would be to revise java.util.Properties to extend Hashtable<String,String>, as suggested, but doing that in a binary-compatible way first requires that 5064052 (unnecessary bridge methods interfere with some generics retrofitting) be fixed. -- ###@###.### 2004/6/16 Unfortunately it proved impossible to revise java.util.Properties to extend Hashtable<String,String> since that would have introduced a subtle binary incompatibility. The relevant APIs have instead been revised to accept arguments of type Hashtable<?,?> rather than their current, more-specific types. -- ###@###.### 2004/7/16
07-12-0182