src/share/classes/com/sun/jndi/ldap/LdapAttribute.java

Print this page

        

@@ -24,12 +24,10 @@
  */
 
 package com.sun.jndi.ldap;
 
 import java.io.IOException;
-import java.io.Serializable;
-import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Vector;
 import javax.naming.*;
 import javax.naming.directory.*;
 

@@ -48,15 +46,16 @@
     private Name rdn = new CompositeName();
 
     // these two are used to reconstruct the baseCtx if this attribute has
     // been serialized (
     private String baseCtxURL;
-    private Hashtable baseCtxEnv;
+    private Hashtable<String, ? super String> baseCtxEnv;
 
+    @SuppressWarnings("unchecked") // clone()
     public Object clone() {
         LdapAttribute attr = new LdapAttribute(this.attrID, baseCtx, rdn);
-        attr.values = (Vector)values.clone();
+        attr.values = (Vector<Object>)values.clone();
         return attr;
     }
 
     /**
       * Adds a new value to this attribute.

@@ -110,11 +109,11 @@
      * to which calls are made.
      */
     private DirContext getBaseCtx() throws NamingException {
         if(baseCtx == null) {
             if (baseCtxEnv == null) {
-                baseCtxEnv = new Hashtable(3);
+                baseCtxEnv = new Hashtable<String, String>(3);
             }
             baseCtxEnv.put(Context.INITIAL_CONTEXT_FACTORY,
                              "com.sun.jndi.ldap.LdapCtxFactory");
             baseCtxEnv.put(Context.PROVIDER_URL,baseCtxURL);
             baseCtx = (new InitialDirContext(baseCtxEnv));

@@ -142,32 +141,31 @@
     /**
      * sets the information needed to reconstruct the baseCtx if
      * we are serialized. This must be called _before_ the object is
      * serialized!!!
      */
+    @SuppressWarnings("unchecked") // clone()
     private void setBaseCtxInfo() {
-        Hashtable realEnv = null;
-        Hashtable secureEnv = null;
+        Hashtable<String, Object> realEnv = null;
+        Hashtable<String, Object> secureEnv = null;
 
         if (baseCtx != null) {
             realEnv = ((LdapCtx)baseCtx).envprops;
             this.baseCtxURL = ((LdapCtx)baseCtx).getURL();
         }
 
         if(realEnv != null && realEnv.size() > 0 ) {
             // remove any security credentials - otherwise the serialized form
             // would store them in the clear
-            Enumeration keys = realEnv.keys();
-            while(keys.hasMoreElements()) {
-                String key = (String)keys.nextElement();
+            for (String key : realEnv.keySet()){
                 if (key.indexOf("security") != -1 ) {
 
                     //if we need to remove props, we must do it to a clone
                     //of the environment. cloning is expensive, so we only do
                     //it if we have to.
                     if(secureEnv == null) {
-                        secureEnv = (Hashtable)realEnv.clone();
+                        secureEnv = (Hashtable<String, Object>)realEnv.clone();
                     }
                     secureEnv.remove(key);
                 }
             }
         }