United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5054615 Generification conflict: Properties vs. javax.naming.InitialContext
JDK-5054615 : Generification conflict: Properties vs. javax.naming.InitialContext

Details
Type:
Bug
Submit Date:
2004-05-28
Status:
Resolved
Updated Date:
2004-07-21
Project Name:
JDK
Resolved Date:
2004-07-21
Component:
core-libs
OS:
solaris_8
Sub-Component:
java.util
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
5.0 (b59)

Related Reports
Relates:

Sub Tasks

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
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
                                     
182-12-07 0
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger-rc

FIXED IN:
tiger-rc

INTEGRATED IN:
tiger-b59
tiger-rc


                                     
2004-08-03



Hardware and Software, Engineered to Work Together