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

Print this page

        

@@ -221,20 +221,20 @@
 
     int port_number;                    // port number of server
     String hostname = null;             // host name of server (no brackets
                                         //   for IPv6 literals)
     LdapClient clnt = null;             // connection handle
-    Hashtable envprops = null;          // environment properties of context
+    Hashtable<String, java.lang.Object> envprops = null; // environment properties of context
     int handleReferrals = DEFAULT_REFERRAL_MODE; // how referral is handled
     boolean hasLdapsScheme = false;     // true if the context was created
                                         //  using an LDAPS URL.
 
         // ------- Not inherited by derived context instances
 
     String currentDN;                   // DN of this context
     Name currentParsedDN;               // DN of this context
-    Vector respCtls = null;             // Response controls read
+    Vector<Control> respCtls = null;    // Response controls read
     Control[] reqCtls = null;           // Controls to be sent with each request
 
 
     // ------------- Private instance variables ------------------------
 

@@ -242,18 +242,18 @@
 
     private OutputStream trace = null;  // output stream for BER debug output
     private boolean netscapeSchemaBug = false;       // workaround
     private Control[] bindCtls = null;  // Controls to be sent with LDAP "bind"
     private int referralHopLimit = DEFAULT_REFERRAL_LIMIT;  // max referral
-    private Hashtable schemaTrees = null; // schema root of this context
+    private Hashtable<String, DirContext> schemaTrees = null; // schema root of this context
     private int batchSize = DEFAULT_BATCH_SIZE;      // batch size for search results
     private boolean deleteRDN = DEFAULT_DELETE_RDN;  // delete the old RDN when modifying DN
     private boolean typesOnly = DEFAULT_TYPES_ONLY;  // return attribute types (no values)
     private int derefAliases = DEFAULT_DEREF_ALIASES;// de-reference alias entries during searching
     private char addrEncodingSeparator = DEFAULT_REF_SEPARATOR;  // encoding RefAddr
 
-    private Hashtable binaryAttrs = null;    // attr values returned as byte[]
+    private Hashtable<String, Boolean> binaryAttrs = null; // attr values returned as byte[]
     private int connectTimeout = -1;         // no timeout value
     private int readTimeout = -1;            // no timeout value
     private boolean waitForReply = true;     // wait for search response
     private int replyQueueSize  = -1;        // unlimited queue size
     private boolean useSsl = false;          // true if SSL protocol is active

@@ -270,17 +270,19 @@
     private boolean unsolicited = false;     // if there unsolicited listeners
     private boolean sharable = true;         // can share connection with other ctx
 
     // -------------- Constructors  -----------------------------------
 
-    public LdapCtx(String dn, String host, int port_number, Hashtable props,
+    @SuppressWarnings("unchecked")
+    public LdapCtx(String dn, String host, int port_number,
+            Hashtable<?,?> props,
             boolean useSsl) throws NamingException {
 
         this.useSsl = this.hasLdapsScheme = useSsl;
 
         if (props != null) {
-            envprops = (Hashtable) props.clone();
+            envprops = (Hashtable<String, java.lang.Object>) props.clone();
 
             // SSL env prop overrides the useSsl argument
             if ("ssl".equals(envprops.get(Context.SECURITY_PROTOCOL))) {
                 this.useSsl = true;
             }

@@ -308,11 +310,11 @@
         } else {
             this.port_number = this.useSsl ? DEFAULT_SSL_PORT : DEFAULT_PORT;
             this.useDefaultPortNumber = true;
         }
 
-        schemaTrees = new Hashtable(11, 0.75f);
+        schemaTrees = new Hashtable<>(11, 0.75f);
         initEnv();
         try {
             connect(false);
         } catch (NamingException e) {
             try {

@@ -916,23 +918,21 @@
             if (dn.equals("")) {
                 return attrs;
             }
 
             // Parse string name into list of RDNs
-            //List<Rdn> rdnList = (new LdapName(dn)).rdns();
-            List rdnList = (new LdapName(dn)).getRdns();
+            List<Rdn> rdnList = (new LdapName(dn)).getRdns();
 
             // Get leaf RDN
-            //Rdn rdn = rdnList.get(rdnList.size() - 1);
-            Rdn rdn = (Rdn) rdnList.get(rdnList.size() - 1);
+            Rdn rdn = rdnList.get(rdnList.size() - 1);
             Attributes nameAttrs = rdn.toAttributes();
 
             // Add attributes of RDN to attrs if not already there
-            NamingEnumeration enum_ = nameAttrs.getAll();
+            NamingEnumeration<? extends Attribute> enum_ = nameAttrs.getAll();
             Attribute nameAttr;
             while (enum_.hasMore()) {
-                nameAttr = (Attribute) enum_.next();
+                nameAttr = enum_.next();
 
                 // If attrs already has the attribute, don't change or add to it
                 if (attrs.get(nameAttr.getID()) ==  null) {
 
                     /**

@@ -959,16 +959,16 @@
 
             return attrs;
     }
 
 
-    private static boolean containsIgnoreCase(NamingEnumeration enumStr,
+    private static boolean containsIgnoreCase(NamingEnumeration<String> enumStr,
                                 String str) throws NamingException {
         String strEntry;
 
         while (enumStr.hasMore()) {
-             strEntry = (String) enumStr.next();
+             strEntry = enumStr.next();
              if (strEntry.equalsIgnoreCase(str)) {
                 return true;
              }
         }
         return false;

@@ -991,11 +991,11 @@
 
     /*
      * Append the the second Vector onto the first Vector
      * (v2 must be non-null)
      */
-    private static Vector appendVector(Vector v1, Vector v2) {
+    private static <T> Vector<T> appendVector(Vector<T> v1, Vector<T> v2) {
         if (v1 == null) {
             v1 = v2;
         } else {
             for (int i = 0; i < v2.size(); i++) {
                 v1.addElement(v2.elementAt(i));

@@ -1036,14 +1036,14 @@
 
             if (answer.entries == null || answer.entries.size() != 1) {
                 // found it but got no attributes
                 attrs = new BasicAttributes(LdapClient.caseIgnore);
             } else {
-                LdapEntry entry = (LdapEntry)answer.entries.elementAt(0);
+                LdapEntry entry = answer.entries.elementAt(0);
                 attrs = entry.attributes;
 
-                Vector entryCtls = entry.respCtls; // retrieve entry controls
+                Vector<Control> entryCtls = entry.respCtls; // retrieve entry controls
                 if (entryCtls != null) {
                     appendVector(respCtls, entryCtls); // concatenate controls
                 }
             }
 

@@ -1095,11 +1095,11 @@
             e2.setRootCause(e);
             throw cont.fillInException(e2);
         }
     }
 
-    protected NamingEnumeration c_list(Name name, Continuation cont)
+    protected NamingEnumeration<NameClassPair> c_list(Name name, Continuation cont)
             throws NamingException {
         SearchControls cons = new SearchControls();
         String[] classAttrs = new String[2];
 
         classAttrs[0] = Obj.JAVA_ATTRIBUTES[Obj.OBJECT_CLASS];

@@ -1168,11 +1168,12 @@
         } catch (NamingException e) {
             throw cont.fillInException(e);
         }
     }
 
-    protected NamingEnumeration c_listBindings(Name name, Continuation cont)
+    @SuppressWarnings("unchecked")
+    protected NamingEnumeration<Binding> c_listBindings(Name name, Continuation cont)
             throws NamingException {
 
         SearchControls cons = new SearchControls();
         cons.setReturningAttributes(null); // ask for all attributes
         cons.setReturningObjFlag(true); // need values to construct obj

@@ -1188,11 +1189,12 @@
             if ((answer.status != LdapClient.LDAP_SUCCESS) ||
                 (answer.referrals != null)) {
                 processReturnCode(answer, name);
             }
 
-            return new LdapBindingEnumeration(this, answer, name, cont);
+            return (NamingEnumeration)
+                    new LdapBindingEnumeration(this, answer, name, cont);
 
         } catch (LdapReferralException e) {
             if (handleReferrals == LdapClient.LDAP_REF_THROW)
                 throw cont.fillInException(e);
 

@@ -1220,19 +1222,19 @@
             LdapBindingEnumeration res =
                 new LdapBindingEnumeration(this, answer, name, cont);
 
             res.setNamingException(
                     (LimitExceededException)cont.fillInException(e));
-            return res;
+            return (NamingEnumeration)res;
 
         } catch (PartialResultException e) {
             LdapBindingEnumeration res =
                 new LdapBindingEnumeration(this, answer, name, cont);
 
             res.setNamingException(
                     (PartialResultException)cont.fillInException(e));
-            return res;
+            return (NamingEnumeration)res;
 
         } catch (NamingException e) {
             throw cont.fillInException(e);
         }
     }

@@ -1335,13 +1337,13 @@
             if (answer.entries == null || answer.entries.size() != 1) {
                 return new BasicAttributes(LdapClient.caseIgnore);
             }
 
             // get attributes from result
-            LdapEntry entry = (LdapEntry) answer.entries.elementAt(0);
+            LdapEntry entry = answer.entries.elementAt(0);
 
-            Vector entryCtls = entry.respCtls; // retrieve entry controls
+            Vector<Control> entryCtls = entry.respCtls; // retrieve entry controls
             if (entryCtls != null) {
                 appendVector(respCtls, entryCtls); // concatenate controls
             }
 
             // do this so attributes can find their schema

@@ -1396,14 +1398,14 @@
 
             // construct mod list
             int[] jmods = new int[attrs.size()];
             Attribute[] jattrs = new Attribute[attrs.size()];
 
-            NamingEnumeration ae = attrs.getAll();
+            NamingEnumeration<? extends Attribute> ae = attrs.getAll();
             for(int i = 0; i < jmods.length && ae.hasMore(); i++) {
                 jmods[i] = jmod_op;
-                jattrs[i] = (Attribute)ae.next();
+                jattrs[i] = ae.next();
             }
 
             LdapResult answer = clnt.modify(newDN, jmods, jattrs, reqCtls);
             respCtls = answer.resControls; // retrieve response controls
 

@@ -1563,11 +1565,11 @@
             // create a context to hold the schema objects representing the object
             // classes
             HierMemDirCtx objectClassCtx = new HierMemDirCtx();
             DirContext objectClassDef;
             String objectClassName;
-            for (Enumeration objectClasses = objectClassAttr.getAll();
+            for (Enumeration<?> objectClasses = objectClassAttr.getAll();
                 objectClasses.hasMoreElements(); ) {
                 objectClassName = (String)objectClasses.nextElement();
                 // %%% Should we fail if not found, or just continue?
                 objectClassDef = (DirContext)ocSchema.lookup(objectClassName);
                 objectClassCtx.bind(objectClassName, objectClassDef);

@@ -1589,11 +1591,11 @@
      * stores it in our private hash table
      */
     private DirContext getSchemaTree(Name name) throws NamingException {
         String subschemasubentry = getSchemaEntry(name, true);
 
-        DirContext schemaTree = (DirContext)schemaTrees.get(subschemasubentry);
+        DirContext schemaTree = schemaTrees.get(subschemasubentry);
 
         if(schemaTree==null) {
             if(debug){System.err.println("LdapCtx: building new schema tree " + this);}
             schemaTree = buildSchemaTree(subschemasubentry);
             schemaTrees.put(subschemasubentry, schemaTree);

@@ -1619,19 +1621,19 @@
                 SCHEMA_ATTRIBUTES /* return schema attrs */,
                 true /* return obj */,
                 false /*deref link */ );
 
         Name sse = (new CompositeName()).add(subschemasubentry);
-        NamingEnumeration results =
+        NamingEnumeration<SearchResult> results =
             searchAux(sse, "(objectClass=subschema)", constraints,
             false, true, new Continuation());
 
         if(!results.hasMore()) {
             throw new OperationNotSupportedException(
                 "Cannot get read subschemasubentry: " + subschemasubentry);
         }
-        SearchResult result = (SearchResult)results.next();
+        SearchResult result = results.next();
         results.close();
 
         Object obj = result.getObject();
         if(!(obj instanceof LdapCtx)) {
             throw new NamingException(

@@ -1672,11 +1674,11 @@
             0, 0, /* count and time limits */
             new String[]{"subschemasubentry"} /* attr to return */,
             false /* returning obj */,
             false /* deref link */);
 
-        NamingEnumeration results;
+        NamingEnumeration<SearchResult> results;
         try {
             results = searchAux(name, "objectclass=*", constraints, relative,
                 true, new Continuation());
 
         } catch (NamingException ne) {

@@ -1693,11 +1695,11 @@
         if (!results.hasMoreElements()) {
             throw new ConfigurationException(
                 "Requesting schema of nonexistent entry: " + name);
         }
 
-        SearchResult result = (SearchResult) results.next();
+        SearchResult result = results.next();
         results.close();
 
         Attribute schemaEntryAttr =
             result.getAttributes().get("subschemasubentry");
         //System.err.println("schema entry attrs: " + schemaEntryAttr);

@@ -1718,11 +1720,11 @@
 
     // package-private; used by search enum.
     // Set attributes to point to this context in case some one
     // asked for their schema
     void setParents(Attributes attrs, Name name) throws NamingException {
-        NamingEnumeration ae = attrs.getAll();
+        NamingEnumeration<? extends Attribute> ae = attrs.getAll();
         while(ae.hasMore()) {
             ((LdapAttribute) ae.next()).setParent(this, name);
         }
     }
 

@@ -1738,18 +1740,18 @@
 
         return url;
     }
 
    // --------------------- Searches -----------------------------
-    protected NamingEnumeration c_search(Name name,
+    protected NamingEnumeration<SearchResult> c_search(Name name,
                                          Attributes matchingAttributes,
                                          Continuation cont)
             throws NamingException {
         return c_search(name, matchingAttributes, null, cont);
     }
 
-    protected NamingEnumeration c_search(Name name,
+    protected NamingEnumeration<SearchResult> c_search(Name name,
                                          Attributes matchingAttributes,
                                          String[] attributesToReturn,
                                          Continuation cont)
             throws NamingException {
         SearchControls cons = new SearchControls();

@@ -1762,20 +1764,20 @@
             throw cont.fillInException(e);
         }
         return c_search(name, filter, cons, cont);
     }
 
-    protected NamingEnumeration c_search(Name name,
+    protected NamingEnumeration<SearchResult> c_search(Name name,
                                          String filter,
                                          SearchControls cons,
                                          Continuation cont)
             throws NamingException {
         return searchAux(name, filter, cloneSearchControls(cons), true,
                  waitForReply, cont);
     }
 
-    protected NamingEnumeration c_search(Name name,
+    protected NamingEnumeration<SearchResult> c_search(Name name,
                                          String filterExpr,
                                          Object[] filterArgs,
                                          SearchControls cons,
                                          Continuation cont)
             throws NamingException {

@@ -1788,11 +1790,12 @@
         }
         return c_search(name, strfilter, cons, cont);
     }
 
         // Used by NamingNotifier
-    NamingEnumeration searchAux(Name name,
+    @SuppressWarnings("unchecked")
+    NamingEnumeration<SearchResult> searchAux(Name name,
         String filter,
         SearchControls cons,
         boolean relative,
         boolean waitForReply, Continuation cont) throws NamingException {
 

@@ -1846,11 +1849,12 @@
             } else {
                 answer = doSearch(name, filter, cons, relative, waitForReply);
                 // search result may contain referrals
                 processReturnCode(answer, name);
             }
-            return new LdapSearchEnumeration(this, answer,
+            return (NamingEnumeration)
+                new LdapSearchEnumeration(this, answer,
                 fullyQualifiedName(name), args, cont);
 
         } catch (LdapReferralException e) {
             if (handleReferrals == LdapClient.LDAP_REF_THROW)
                 throw cont.fillInException(e);

@@ -1879,19 +1883,19 @@
         } catch (LimitExceededException e) {
             LdapSearchEnumeration res =
                 new LdapSearchEnumeration(this, answer, fullyQualifiedName(name),
                                           args, cont);
             res.setNamingException(e);
-            return res;
+            return (NamingEnumeration)res;
 
         } catch (PartialResultException e) {
             LdapSearchEnumeration res =
                 new LdapSearchEnumeration(this, answer, fullyQualifiedName(name),
                                           args, cont);
 
             res.setNamingException(e);
-            return res;
+            return (NamingEnumeration)res;
 
         } catch (IOException e) {
             NamingException e2 = new CommunicationException(e.getMessage());
             e2.setRootCause(e);
             throw cont.fillInException(e2);

@@ -2141,137 +2145,170 @@
    // -------------- Environment Properties ------------------
 
     /**
      * Override with noncloning version.
      */
-    protected Hashtable p_getEnvironment() {
+    protected Hashtable<String, Object> p_getEnvironment() {
         return envprops;
     }
 
-    public Hashtable getEnvironment() throws NamingException {
+    @SuppressWarnings("unchecked")
+    public Hashtable<String, Object> getEnvironment() throws NamingException {
         return (envprops == null
-                ? new Hashtable(5, 0.75f)
-                : (Hashtable)envprops.clone());
+                ? new Hashtable<String, Object>(5, 0.75f)
+                : (Hashtable<String, Object>)envprops.clone());
     }
 
+    @SuppressWarnings("unchecked")
     public Object removeFromEnvironment(String propName)
         throws NamingException {
 
         // not there; just return
         if (envprops == null || envprops.get(propName) == null) {
             return null;
         }
-
-        if (propName.equals(REF_SEPARATOR)) {
+        switch (propName) {
+            case REF_SEPARATOR:
             addrEncodingSeparator = DEFAULT_REF_SEPARATOR;
-        } else if (propName.equals(TYPES_ONLY)) {
+                break;
+            case TYPES_ONLY:
             typesOnly = DEFAULT_TYPES_ONLY;
-        } else if (propName.equals(DELETE_RDN)) {
+                break;
+            case DELETE_RDN:
             deleteRDN = DEFAULT_DELETE_RDN;
-        } else if (propName.equals(DEREF_ALIASES)) {
+                break;
+            case DEREF_ALIASES:
             derefAliases = DEFAULT_DEREF_ALIASES;
-        } else if (propName.equals(Context.BATCHSIZE)) {
+                break;
+            case Context.BATCHSIZE:
             batchSize = DEFAULT_BATCH_SIZE;
-        } else if (propName.equals(REFERRAL_LIMIT)) {
+                break;
+            case REFERRAL_LIMIT:
             referralHopLimit = DEFAULT_REFERRAL_LIMIT;
-        } else if (propName.equals(Context.REFERRAL)) {
+                break;
+            case Context.REFERRAL:
             setReferralMode(null, true);
-        } else if (propName.equals(BINARY_ATTRIBUTES)) {
+                break;
+            case BINARY_ATTRIBUTES:
             setBinaryAttributes(null);
-        } else if (propName.equals(CONNECT_TIMEOUT)) {
+                break;
+            case CONNECT_TIMEOUT:
             connectTimeout = -1;
-        } else if (propName.equals(READ_TIMEOUT)) {
+                break;
+            case READ_TIMEOUT:
             readTimeout = -1;
-        } else if (propName.equals(WAIT_FOR_REPLY)) {
+                break;
+            case WAIT_FOR_REPLY:
             waitForReply = true;
-        } else if (propName.equals(REPLY_QUEUE_SIZE)) {
+                break;
+            case REPLY_QUEUE_SIZE:
             replyQueueSize = -1;
+                break;
 
-// The following properties affect the connection
+            // The following properties affect the connection
 
-        } else if (propName.equals(Context.SECURITY_PROTOCOL)) {
+            case Context.SECURITY_PROTOCOL:
             closeConnection(SOFT_CLOSE);
             // De-activate SSL and reset the context's url and port number
             if (useSsl && !hasLdapsScheme) {
                 useSsl = false;
                 url = null;
                 if (useDefaultPortNumber) {
                     port_number = DEFAULT_PORT;
                 }
             }
-        } else if (propName.equals(VERSION) ||
-            propName.equals(SOCKET_FACTORY)) {
+                break;
+            case VERSION:
+            case SOCKET_FACTORY:
             closeConnection(SOFT_CLOSE);
-        } else if(propName.equals(Context.SECURITY_AUTHENTICATION) ||
-            propName.equals(Context.SECURITY_PRINCIPAL) ||
-            propName.equals(Context.SECURITY_CREDENTIALS)) {
+                break;
+            case Context.SECURITY_AUTHENTICATION:
+            case Context.SECURITY_PRINCIPAL:
+            case Context.SECURITY_CREDENTIALS:
             sharable = false;
+                break;
         }
 
         // Update environment; reconnection will use new props
-        envprops = (Hashtable)envprops.clone();
+        envprops = (Hashtable<String, Object>)envprops.clone();
         return envprops.remove(propName);
     }
 
+    @SuppressWarnings("unchecked")
     public Object addToEnvironment(String propName, Object propVal)
         throws NamingException {
 
             // If adding null, call remove
             if (propVal == null) {
                 return removeFromEnvironment(propName);
             }
-
-            if (propName.equals(REF_SEPARATOR)) {
+        switch (propName) {
+            case REF_SEPARATOR:
                 setRefSeparator((String)propVal);
-            } else if (propName.equals(TYPES_ONLY)) {
+                break;
+            case TYPES_ONLY:
                 setTypesOnly((String)propVal);
-            } else if (propName.equals(DELETE_RDN)) {
+                break;
+            case DELETE_RDN:
                 setDeleteRDN((String)propVal);
-            } else if (propName.equals(DEREF_ALIASES)) {
+                break;
+            case DEREF_ALIASES:
                 setDerefAliases((String)propVal);
-            } else if (propName.equals(Context.BATCHSIZE)) {
+                break;
+            case Context.BATCHSIZE:
                 setBatchSize((String)propVal);
-            } else if (propName.equals(REFERRAL_LIMIT)) {
+                break;
+            case REFERRAL_LIMIT:
                 setReferralLimit((String)propVal);
-            } else if (propName.equals(Context.REFERRAL)) {
+                break;
+            case Context.REFERRAL:
                 setReferralMode((String)propVal, true);
-            } else if (propName.equals(BINARY_ATTRIBUTES)) {
+                break;
+            case BINARY_ATTRIBUTES:
                 setBinaryAttributes((String)propVal);
-            } else if (propName.equals(CONNECT_TIMEOUT)) {
+                break;
+            case CONNECT_TIMEOUT:
                 setConnectTimeout((String)propVal);
-            } else if (propName.equals(READ_TIMEOUT)) {
+                break;
+            case READ_TIMEOUT:
                 setReadTimeout((String)propVal);
-            } else if (propName.equals(WAIT_FOR_REPLY)) {
+                break;
+            case WAIT_FOR_REPLY:
                 setWaitForReply((String)propVal);
-            } else if (propName.equals(REPLY_QUEUE_SIZE)) {
+                break;
+            case REPLY_QUEUE_SIZE:
                 setReplyQueueSize((String)propVal);
+                break;
 
 // The following properties affect the connection
 
-            } else if (propName.equals(Context.SECURITY_PROTOCOL)) {
+            case Context.SECURITY_PROTOCOL:
                 closeConnection(SOFT_CLOSE);
                 // Activate SSL and reset the context's url and port number
                 if ("ssl".equals(propVal)) {
                     useSsl = true;
                     url = null;
                     if (useDefaultPortNumber) {
                         port_number = DEFAULT_SSL_PORT;
                     }
                 }
-            } else if (propName.equals(VERSION) ||
-                propName.equals(SOCKET_FACTORY)) {
+                break;
+            case VERSION:
+            case SOCKET_FACTORY:
                 closeConnection(SOFT_CLOSE);
-            } else if (propName.equals(Context.SECURITY_AUTHENTICATION) ||
-                propName.equals(Context.SECURITY_PRINCIPAL) ||
-                propName.equals(Context.SECURITY_CREDENTIALS)) {
+                break;
+            case Context.SECURITY_AUTHENTICATION:
+            case Context.SECURITY_PRINCIPAL:
+            case Context.SECURITY_CREDENTIALS:
                 sharable = false;
+                break;
             }
 
             // Update environment; reconnection will use new props
             envprops = (envprops == null
-                ? new Hashtable(5, 0.75f)
-                : (Hashtable)envprops.clone());
+                ? new Hashtable<String, Object>(5, 0.75f)
+                : (Hashtable<String, Object>)envprops.clone());
             return envprops.put(propName, propVal);
     }
 
     /**
      * Sets the URL that created the context in the java.naming.provider.url

@@ -2378,17 +2415,21 @@
      * If referral mode is 'ignore' then activate the manageReferral control.
      */
     private void setReferralMode(String ref, boolean update) {
         // First determine the referral mode
         if (ref != null) {
-            if (ref.equals("follow")) {
+            switch (ref) {
+                case "follow":
                 handleReferrals = LdapClient.LDAP_REF_FOLLOW;
-            } else if (ref.equals("throw")) {
+                    break;
+                case "throw":
                 handleReferrals = LdapClient.LDAP_REF_THROW;
-            } else if (ref.equals("ignore")) {
+                    break;
+                case "ignore":
                 handleReferrals = LdapClient.LDAP_REF_IGNORE;
-            } else {
+                    break;
+                default:
                 throw new IllegalArgumentException(
                     "Illegal value for " + Context.REFERRAL + " property.");
             }
         } else {
             handleReferrals = DEFAULT_REFERRAL_MODE;

@@ -2409,19 +2450,24 @@
     /**
      * Set whether aliases are derefereced during resolution and searches.
      */
     private void setDerefAliases(String deref) {
         if (deref != null) {
-            if (deref.equals("never")) {
+            switch (deref) {
+                case "never":
                 derefAliases = 0; // never de-reference aliases
-            } else if (deref.equals("searching")) {
+                    break;
+                case "searching":
                 derefAliases = 1; // de-reference aliases during searching
-            } else if (deref.equals("finding")) {
+                    break;
+                case "finding":
                 derefAliases = 2; // de-reference during name resolution
-            } else if (deref.equals("always")) {
+                    break;
+                case "always":
                 derefAliases = 3; // always de-reference aliases
-            } else {
+                    break;
+                default:
                 throw new IllegalArgumentException("Illegal value for " +
                     DEREF_ALIASES + " property.");
             }
         } else {
             derefAliases = DEFAULT_DEREF_ALIASES;

@@ -2513,22 +2559,22 @@
      *     <urlstring > ::= "Referral:" <ldapurls>
      *     <ldapurls>   ::= <separator> <ldapurl> | <ldapurls>
      *     <separator>  ::= ASCII linefeed character (0x0a)
      *     <ldapurl>    ::= LDAP URL format (RFC 1959)
      */
-    private static Vector extractURLs(String refString) {
+    private static Vector<String> extractURLs(String refString) {
 
         int separator = 0;
         int urlCount = 0;
 
         // count the number of URLs
         while ((separator = refString.indexOf('\n', separator)) >= 0) {
             separator++;
             urlCount++;
         }
 
-        Vector referrals = new Vector(urlCount);
+        Vector<String> referrals = new Vector<>(urlCount);
         int iURL;
         int i = 0;
 
         separator = refString.indexOf('\n');
         iURL = separator + 1;

@@ -2547,11 +2593,11 @@
      */
     private void setBinaryAttributes(String attrIds) {
         if (attrIds == null) {
             binaryAttrs = null;
         } else {
-            binaryAttrs = new Hashtable(11, 0.75f);
+            binaryAttrs = new Hashtable<>(11, 0.75f);
             StringTokenizer tokens =
                 new StringTokenizer(attrIds.toLowerCase(), " ");
 
             while (tokens.hasMoreTokens()) {
                 binaryAttrs.put(tokens.nextToken(), Boolean.TRUE);

@@ -2599,15 +2645,16 @@
         schemaTrees = null;
         envprops = null;
 */
     }
 
+    @SuppressWarnings("unchecked")
     public void reconnect(Control[] connCtls) throws NamingException {
         // Update environment
         envprops = (envprops == null
-                ? new Hashtable(5, 0.75f)
-                : (Hashtable)envprops.clone());
+                ? new Hashtable<String, Object>(5, 0.75f)
+                : (Hashtable<String, Object>)envprops.clone());
 
         if (connCtls == null) {
             envprops.remove(BIND_CONTROLS);
             bindCtls = null;
         } else {

@@ -2629,11 +2676,11 @@
                 if (debug) {
                     System.err.println("LdapCtx: Reconnecting " + this);
                 }
 
                 // reset the cache before a new connection is established
-                schemaTrees = new Hashtable(11, 0.75f);
+                schemaTrees = new Hashtable<>(11, 0.75f);
                 connect(startTLS);
 
             } else if (!sharable || startTLS) {
 
                 synchronized (clnt) {

@@ -2642,11 +2689,11 @@
                         || clnt.usingSaslStreams()) {
                         closeConnection(SOFT_CLOSE);
                     }
                 }
                 // reset the cache before a new connection is established
-                schemaTrees = new Hashtable(11, 0.75f);
+                schemaTrees = new Hashtable<>(11, 0.75f);
                 connect(startTLS);
             }
 
         } finally {
             sharable = true;   // connection is now either new or single-use

@@ -2844,11 +2891,11 @@
                           envprops,
                           fullyQualifiedName(remainName));
     }
 
     protected void processReturnCode(LdapResult res, Name resolvedName,
-        Object resolvedObj, Name remainName, Hashtable envprops, String fullDN)
+        Object resolvedObj, Name remainName, Hashtable<?,?> envprops, String fullDN)
     throws NamingException {
 
         String msg = LdapClient.getErrorMessage(res.status, res.errorMessage);
         NamingException e;
         LdapReferralException r = null;

@@ -2964,11 +3011,13 @@
                 break;
             }
 
             // extract SLAPD-style referrals from errorMessage
             if ((res.errorMessage != null) && (!res.errorMessage.equals(""))) {
-                res.referrals = extractURLs(res.errorMessage);
+                @SuppressWarnings("unchecked")
+                Vector<Object> temp = (Vector)extractURLs(res.errorMessage);
+                res.referrals = temp;
             } else {
                 e = new PartialResultException(msg);
                 break;
             }
 

@@ -2996,11 +3045,11 @@
              *     assume name resolution has not yet completed.
              */
             if (((res.entries == null) || (res.entries.size() == 0)) &&
                 (res.referrals.size() == 1)) {
 
-                r.setReferralInfo((Vector)res.referrals, false);
+                r.setReferralInfo(res.referrals, false);
 
                 // check the hop limit
                 if (hopCount > referralHopLimit) {
                     NamingException lee =
                         new LimitExceededException("Referral limit exceeded");

@@ -3282,13 +3331,13 @@
         return (respCtls != null)? convertControls(respCtls) : null;
     }
 
     /**
      * Narrow controls using own default factory and ControlFactory.
-     * @param ctls A non-null Vector
+     * @param ctls A non-null Vector<Control>
      */
-    Control[] convertControls(Vector ctls) throws NamingException {
+    Control[] convertControls(Vector<Control> ctls) throws NamingException {
         int count = ctls.size();
 
         if (count == 0) {
             return null;
         }

@@ -3296,16 +3345,16 @@
         Control[] controls = new Control[count];
 
         for (int i = 0; i < count; i++) {
             // Try own factory first
             controls[i] = myResponseControlFactory.getControlInstance(
-                (Control)ctls.elementAt(i));
+                ctls.elementAt(i));
 
             // Try assigned factories if own produced null
             if (controls[i] == null) {
                 controls[i] = ControlFactory.getControlInstance(
-                (Control)ctls.elementAt(i), this, envprops);
+                ctls.elementAt(i), this, envprops);
             }
         }
         return controls;
     }