changeset 8596:9e334859b240

7072353: JNDI libraries do not build with javac -Xlint:all -Werror 7077672: jdk8_tl nightly fail in step-2 build on 8/10/11 Reviewed-by: xuelei, mchung, jjg Contributed-by: alexandre.boulgakov@oracle.com
author jjg
date Mon, 30 Jan 2017 08:02:44 +0000
parents 21d88f84ccbe
children 86ebe8c365f1
files make/com/sun/jndi/Makefile make/javax/others/Makefile src/share/classes/com/sun/jndi/cosnaming/CNBindingEnumeration.java src/share/classes/com/sun/jndi/cosnaming/CNCtx.java src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java src/share/classes/com/sun/jndi/cosnaming/ExceptionMapper.java src/share/classes/com/sun/jndi/cosnaming/IiopUrl.java src/share/classes/com/sun/jndi/dns/DnsContext.java src/share/classes/com/sun/jndi/dns/DnsContextFactory.java src/share/classes/com/sun/jndi/dns/DnsName.java src/share/classes/com/sun/jndi/dns/NameNode.java src/share/classes/com/sun/jndi/dns/Resolver.java src/share/classes/com/sun/jndi/dns/ResourceRecords.java src/share/classes/com/sun/jndi/dns/ZoneNode.java src/share/classes/com/sun/jndi/ldap/AbstractLdapNamingEnumeration.java src/share/classes/com/sun/jndi/ldap/Ber.java src/share/classes/com/sun/jndi/ldap/ClientId.java src/share/classes/com/sun/jndi/ldap/Connection.java src/share/classes/com/sun/jndi/ldap/DigestClientId.java src/share/classes/com/sun/jndi/ldap/EventQueue.java src/share/classes/com/sun/jndi/ldap/EventSupport.java src/share/classes/com/sun/jndi/ldap/LdapAttribute.java src/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java src/share/classes/com/sun/jndi/ldap/LdapClient.java src/share/classes/com/sun/jndi/ldap/LdapCtx.java src/share/classes/com/sun/jndi/ldap/LdapCtxFactory.java src/share/classes/com/sun/jndi/ldap/LdapEntry.java src/share/classes/com/sun/jndi/ldap/LdapName.java src/share/classes/com/sun/jndi/ldap/LdapNamingEnumeration.java src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java src/share/classes/com/sun/jndi/ldap/LdapReferralContext.java src/share/classes/com/sun/jndi/ldap/LdapReferralException.java src/share/classes/com/sun/jndi/ldap/LdapResult.java src/share/classes/com/sun/jndi/ldap/LdapSchemaCtx.java src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java src/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java src/share/classes/com/sun/jndi/ldap/NotifierArgs.java src/share/classes/com/sun/jndi/ldap/Obj.java src/share/classes/com/sun/jndi/ldap/ReferralEnumeration.java src/share/classes/com/sun/jndi/ldap/ServiceLocator.java src/share/classes/com/sun/jndi/ldap/SimpleClientId.java src/share/classes/com/sun/jndi/ldap/UnsolicitedResponseImpl.java src/share/classes/com/sun/jndi/ldap/VersionHelper.java src/share/classes/com/sun/jndi/ldap/VersionHelper12.java src/share/classes/com/sun/jndi/ldap/ext/StartTlsResponseImpl.java src/share/classes/com/sun/jndi/ldap/pool/Connections.java src/share/classes/com/sun/jndi/ldap/pool/ConnectionsWeakRef.java src/share/classes/com/sun/jndi/ldap/pool/Pool.java src/share/classes/com/sun/jndi/ldap/pool/PoolCleaner.java src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java src/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java src/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java src/share/classes/com/sun/jndi/rmi/registry/RegistryContextFactory.java src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java src/share/classes/com/sun/jndi/toolkit/ctx/AtomicContext.java src/share/classes/com/sun/jndi/toolkit/ctx/AtomicDirContext.java src/share/classes/com/sun/jndi/toolkit/ctx/ComponentContext.java src/share/classes/com/sun/jndi/toolkit/ctx/ComponentDirContext.java src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeContext.java src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeDirContext.java src/share/classes/com/sun/jndi/toolkit/dir/ContainmentFilter.java src/share/classes/com/sun/jndi/toolkit/dir/ContextEnumerator.java src/share/classes/com/sun/jndi/toolkit/dir/DirSearch.java src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java src/share/classes/com/sun/jndi/toolkit/dir/LazySearchEnumerationImpl.java src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java src/share/classes/com/sun/jndi/toolkit/url/GenericURLDirContext.java src/share/classes/com/sun/jndi/url/dns/dnsURLContext.java src/share/classes/com/sun/jndi/url/dns/dnsURLContextFactory.java src/share/classes/com/sun/jndi/url/iiop/iiopURLContext.java src/share/classes/com/sun/jndi/url/iiop/iiopURLContextFactory.java src/share/classes/com/sun/jndi/url/ldap/ldapURLContext.java src/share/classes/com/sun/jndi/url/ldap/ldapURLContextFactory.java src/share/classes/com/sun/jndi/url/rmi/rmiURLContext.java src/share/classes/com/sun/jndi/url/rmi/rmiURLContextFactory.java src/share/classes/com/sun/naming/internal/FactoryEnumeration.java src/share/classes/com/sun/naming/internal/NamedWeakReference.java src/share/classes/com/sun/naming/internal/ResourceManager.java src/share/classes/com/sun/naming/internal/VersionHelper.java src/share/classes/com/sun/naming/internal/VersionHelper12.java src/share/classes/javax/naming/CompositeName.java src/share/classes/javax/naming/CompoundName.java src/share/classes/javax/naming/InitialContext.java src/share/classes/javax/naming/NameImpl.java src/share/classes/javax/naming/Reference.java src/share/classes/javax/naming/directory/BasicAttribute.java src/share/classes/javax/naming/directory/BasicAttributes.java src/share/classes/javax/naming/ldap/InitialLdapContext.java src/share/classes/javax/naming/ldap/LdapName.java src/share/classes/javax/naming/ldap/Rdn.java src/share/classes/javax/naming/ldap/Rfc2253Parser.java src/share/classes/javax/naming/ldap/StartTlsRequest.java src/share/classes/javax/naming/spi/ContinuationContext.java src/share/classes/javax/naming/spi/ContinuationDirContext.java src/share/classes/javax/naming/spi/DirectoryManager.java src/share/classes/javax/naming/spi/NamingManager.java
diffstat 99 files changed, 2022 insertions(+), 1857 deletions(-) [+]
line wrap: on
line diff
--- a/make/com/sun/jndi/Makefile	Mon Jan 30 06:47:57 2017 +0000
+++ b/make/com/sun/jndi/Makefile	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 #
 
 BUILDDIR = ../../..
+SUBDIRS_MAKEFLAGS += JAVAC_MAX_WARNINGS=true
 include $(BUILDDIR)/common/Defs.gmk
 
 SUBDIRS = toolkit cosnaming ldap rmi dns
--- a/make/javax/others/Makefile	Mon Jan 30 06:47:57 2017 +0000
+++ b/make/javax/others/Makefile	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 #
 
 BUILDDIR = ../..
+JAVAC_MAX_WARNINGS = true
 include $(BUILDDIR)/common/Defs.gmk
 
 #
--- a/src/share/classes/com/sun/jndi/cosnaming/CNBindingEnumeration.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/cosnaming/CNBindingEnumeration.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,8 +32,6 @@
 import java.util.Hashtable;
 
 import org.omg.CosNaming.*;
-import org.omg.CosNaming.NamingContextPackage.*;
-import org.omg.CORBA.*;
 
 import com.sun.jndi.toolkit.corba.CorbaUtils;
 
@@ -46,7 +44,8 @@
   * @author Rosanna Lee
   */
 
-final class CNBindingEnumeration implements NamingEnumeration {
+final class CNBindingEnumeration
+        implements NamingEnumeration<javax.naming.Binding> {
 
     private static final int DEFAULT_BATCHSIZE = 100;
     private BindingListHolder _bindingList; // list of bindings
@@ -54,105 +53,105 @@
     private int counter;                    // pointer in _bindingList
     private int batchsize = DEFAULT_BATCHSIZE;  // how many to ask for each time
     private CNCtx _ctx;                     // ctx to list
-    private Hashtable _env;                 // environment for getObjectInstance
+    private Hashtable<?,?> _env;            // environment for getObjectInstance
     private boolean more = false;           // iterator done?
     private boolean isLookedUpCtx = false;  // iterating on a context beneath this context ?
 
-  /**
-    * Creates a CNBindingEnumeration object.
-    * @param ctx Context to enumerate
-    */
-  CNBindingEnumeration(CNCtx ctx, boolean isLookedUpCtx, Hashtable env) {
-    // Get batch size to use
-    String batch = (env != null ?
-        (String)env.get(javax.naming.Context.BATCHSIZE) : null);
-    if (batch != null) {
-        try {
-            batchsize = Integer.parseInt(batch);
-        } catch (NumberFormatException e) {
-            throw new IllegalArgumentException("Batch size not numeric: " + batch);
+    /**
+     * Creates a CNBindingEnumeration object.
+     * @param ctx Context to enumerate
+     */
+    CNBindingEnumeration(CNCtx ctx, boolean isLookedUpCtx, Hashtable<?,?> env) {
+        // Get batch size to use
+        String batch = (env != null ?
+            (String)env.get(javax.naming.Context.BATCHSIZE) : null);
+        if (batch != null) {
+            try {
+                batchsize = Integer.parseInt(batch);
+            } catch (NumberFormatException e) {
+                throw new IllegalArgumentException("Batch size not numeric: " + batch);
+            }
+        }
+        _ctx = ctx;
+        _ctx.incEnumCount();
+        this.isLookedUpCtx = isLookedUpCtx;
+        _env = env;
+        _bindingList = new BindingListHolder();
+        BindingIteratorHolder _bindingIterH = new BindingIteratorHolder();
+
+        // Perform listing and request that bindings be returned in _bindingIter
+        // Upon return,_bindingList returns a zero length list
+        _ctx._nc.list(0, _bindingList, _bindingIterH);
+
+        _bindingIter = _bindingIterH.value;
+
+        // Get first batch using _bindingIter
+        if (_bindingIter != null) {
+            more = _bindingIter.next_n(batchsize, _bindingList);
+        } else {
+            more = false;
+        }
+        counter = 0;
+    }
+
+    /**
+     * Returns the next binding in the list.
+     * @exception NamingException any naming exception.
+     */
+
+    public javax.naming.Binding next() throws NamingException {
+        if (more && counter >= _bindingList.value.length) {
+            getMore();
+        }
+        if (more && counter < _bindingList.value.length) {
+            org.omg.CosNaming.Binding bndg = _bindingList.value[counter];
+            counter++;
+            return mapBinding(bndg);
+        } else {
+            throw new NoSuchElementException();
         }
     }
-    _ctx = ctx;
-    _ctx.incEnumCount();
-    this.isLookedUpCtx = isLookedUpCtx;
-    _env = env;
-    _bindingList = new BindingListHolder();
-    BindingIteratorHolder _bindingIterH = new BindingIteratorHolder();
 
-    // Perform listing and request that bindings be returned in _bindingIter
-    // Upon return,_bindingList returns a zero length list
-    _ctx._nc.list(0, _bindingList, _bindingIterH);
 
-    _bindingIter = _bindingIterH.value;
-
-    // Get first batch using _bindingIter
-    if (_bindingIter != null) {
-        more = _bindingIter.next_n(batchsize, _bindingList);
-    } else {
-        more = false;
-    }
-    counter = 0;
-  }
-
-  /**
-    * Returns the next binding in the list.
-    * @exception NamingException any naming exception.
-    */
-
-  public java.lang.Object next() throws NamingException {
-      if (more && counter >= _bindingList.value.length) {
-          getMore();
-      }
-      if (more && counter < _bindingList.value.length) {
-          org.omg.CosNaming.Binding bndg = _bindingList.value[counter];
-          counter++;
-          return mapBinding(bndg);
-      } else {
-          throw new NoSuchElementException();
-      }
-  }
-
-
-  /**
+    /**
     * Returns true or false depending on whether there are more bindings.
     * @return boolean value
     */
 
-  public boolean hasMore() throws NamingException {
-      // If there's more, check whether current bindingList has been exhausted,
-      // and if so, try to get more.
-      // If no more, just say so.
-      return more ? (counter < _bindingList.value.length || getMore()) : false;
-  }
+    public boolean hasMore() throws NamingException {
+        // If there's more, check whether current bindingList has been exhausted,
+        // and if so, try to get more.
+        // If no more, just say so.
+        return more ? (counter < _bindingList.value.length || getMore()) : false;
+    }
 
-  /**
-    * Returns true or false depending on whether there are more bindings.
-    * Need to define this to satisfy the Enumeration api requirement.
-    * @return boolean value
-    */
+    /**
+     * Returns true or false depending on whether there are more bindings.
+     * Need to define this to satisfy the Enumeration api requirement.
+     * @return boolean value
+     */
 
-  public boolean hasMoreElements() {
-      try {
-          return hasMore();
-      } catch (NamingException e) {
-          return false;
-      }
-  }
+    public boolean hasMoreElements() {
+        try {
+            return hasMore();
+        } catch (NamingException e) {
+            return false;
+        }
+    }
 
-  /**
+    /**
     * Returns the next binding in the list.
     * @exception NoSuchElementException Thrown when the end of the
     * list is reached.
     */
 
-    public java.lang.Object nextElement() {
+    public javax.naming.Binding nextElement() {
         try {
             return next();
         } catch (NamingException ne) {
             throw new NoSuchElementException();
         }
-  }
+    }
 
     public void close() throws NamingException {
         more = false;
@@ -199,7 +198,7 @@
         return more;
     }
 
-  /**
+    /**
     * Constructs a JNDI Binding object from the COS Naming binding
     * object.
     * @exception NameNotFound No objects under the name.
@@ -237,5 +236,5 @@
         String fullName = CNNameParser.cosNameToInsString(comps);
         jbndg.setNameInNamespace(fullName);
         return jbndg;
-  }
+    }
 }
--- a/src/share/classes/com/sun/jndi/cosnaming/CNCtx.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/cosnaming/CNCtx.java	Mon Jan 30 08:02:44 2017 +0000
@@ -30,7 +30,6 @@
 import javax.naming.spi.ResolveResult;
 
 import java.util.Hashtable;
-import java.util.Vector;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.io.InputStream;
@@ -79,7 +78,7 @@
 
     private NameComponent[] _name = null;
 
-    Hashtable _env; // used by ExceptionMapper
+    Hashtable<String, java.lang.Object> _env; // used by ExceptionMapper
     static final CNNameParser parser = new CNNameParser();
 
     private static final String FED_PROP = "com.sun.jndi.cosnaming.federation";
@@ -117,11 +116,12 @@
       * @param env Environment properties for initializing name service.
       * @exception NamingException Cannot initialize ORB or naming context.
       */
-    CNCtx(Hashtable env) throws NamingException {
+    @SuppressWarnings("unchecked")
+    CNCtx(Hashtable<?,?> env) throws NamingException {
         if (env != null) {
-            env = (Hashtable) env.clone();
+            env = (Hashtable<?,?>)env.clone();
         }
-        _env = env;
+        _env = (Hashtable<String, java.lang.Object>)env;
         federation = "true".equals(env != null ? env.get(FED_PROP) : null);
         initOrbAndRootContext(env);
     }
@@ -132,13 +132,14 @@
     /**
      * This method is used by the iiop and iiopname URL Context factories.
      */
-    public static ResolveResult createUsingURL(String url, Hashtable env)
+    @SuppressWarnings("unchecked")
+    public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
     throws NamingException {
         CNCtx ctx = new CNCtx();
         if (env != null) {
-            env = (Hashtable) env.clone();
+            env = (Hashtable<?,?>) env.clone();
         }
-        ctx._env = env;
+        ctx._env = (Hashtable<String, java.lang.Object>)env;
         String rest = ctx.initUsingUrl(
             env != null ?
                 (org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
@@ -164,8 +165,8 @@
       * @param name The name of this context relative to the root
       */
 
-    CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx, Hashtable env,
-                        NameComponent[]name)
+    CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx,
+          Hashtable<String, java.lang.Object> env, NameComponent[]name)
         throws NamingException {
             if (orb == null || nctx == null)
                 throw new ConfigurationException(
@@ -243,7 +244,7 @@
       * @exception NamingException When an error occurs while initializing the
       * ORB or the naming context.
       */
-    private void initOrbAndRootContext(Hashtable env) throws NamingException {
+    private void initOrbAndRootContext(Hashtable<?,?> env) throws NamingException {
         org.omg.CORBA.ORB inOrb = null;
         String ncIor = null;
 
@@ -272,7 +273,7 @@
 
             // If name supplied in URL, resolve it to a NamingContext
             if (insName.length() > 0) {
-                _name = parser.nameToCosName(parser.parse(insName));
+                _name = CNNameParser.nameToCosName(parser.parse(insName));
                 try {
                     org.omg.CORBA.Object obj = _nc.resolve(_name);
                     _nc = NamingContextHelper.narrow(obj);
@@ -297,7 +298,7 @@
     }
 
 
-    private String initUsingUrl(ORB orb, String url, Hashtable env)
+    private String initUsingUrl(ORB orb, String url, Hashtable<?,?> env)
         throws NamingException {
         if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
             return initUsingIiopUrl(orb, url, env);
@@ -309,7 +310,7 @@
     /**
      * Handles "iiop" and "iiopname" URLs (INS 98-10-11)
      */
-    private String initUsingIiopUrl(ORB defOrb, String url, Hashtable env)
+    private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env)
         throws NamingException {
 
         if (defOrb == null)
@@ -318,12 +319,9 @@
         try {
             IiopUrl parsedUrl = new IiopUrl(url);
 
-            Vector addrs = parsedUrl.getAddresses();
-            IiopUrl.Address addr;
             NamingException savedException = null;
 
-            for (int i = 0; i < addrs.size(); i++) {
-                addr = (IiopUrl.Address)addrs.elementAt(i);
+            for (IiopUrl.Address addr : parsedUrl.getAddresses()) {
 
                 try {
                     try {
@@ -365,7 +363,7 @@
     /**
      * Initializes using "corbaname" URL (INS 99-12-03)
      */
-    private String initUsingCorbanameUrl(ORB orb, String url, Hashtable env)
+    private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env)
         throws NamingException {
 
         if (orb == null)
@@ -758,7 +756,7 @@
                 // as per JNDI spec
 
                 if (leafNotFound(e, path[path.length-1])) {
-                    ; // do nothing
+                    // do nothing
                 } else {
                     throw ExceptionMapper.mapException(e, this, path);
                 }
@@ -856,7 +854,7 @@
       * with a non-null argument
       * @return a list of name-class objects as a NameClassEnumeration.
       */
-    public  NamingEnumeration list(String name) throws NamingException {
+    public  NamingEnumeration<NameClassPair> list(String name) throws NamingException {
             return list(new CompositeName(name));
     }
 
@@ -867,9 +865,10 @@
       * @exception NamingException All exceptions thrown by lookup
       * @return a list of name-class objects as a NameClassEnumeration.
       */
-    public  NamingEnumeration list(Name name)
+    @SuppressWarnings("unchecked")
+    public  NamingEnumeration<NameClassPair> list(Name name)
         throws NamingException {
-            return listBindings(name);
+            return (NamingEnumeration)listBindings(name);
     }
 
     /**
@@ -879,7 +878,7 @@
       * @exception NamingException all exceptions returned by lookup
       * @return a list of bindings as a BindingEnumeration.
       */
-    public  NamingEnumeration listBindings(String name)
+    public  NamingEnumeration<javax.naming.Binding> listBindings(String name)
         throws NamingException {
             return listBindings(new CompositeName(name));
     }
@@ -891,7 +890,7 @@
       * @exception NamingException all exceptions returned by lookup.
       * @return a list of bindings as a BindingEnumeration.
       */
-    public  NamingEnumeration listBindings(Name name)
+    public  NamingEnumeration<javax.naming.Binding> listBindings(Name name)
         throws NamingException {
             if (_nc == null)
                 throw new ConfigurationException(
@@ -1091,11 +1090,12 @@
       * Returns the current environment.
       * @return Environment.
       */
-    public  Hashtable getEnvironment() throws NamingException {
+    @SuppressWarnings("unchecked")
+    public  Hashtable<String, java.lang.Object> getEnvironment() throws NamingException {
         if (_env == null) {
-            return new Hashtable(5, 0.75f);
+            return new Hashtable<>(5, 0.75f);
         } else {
-            return (Hashtable)_env.clone();
+            return (Hashtable<String, java.lang.Object>)_env.clone();
         }
     }
 
@@ -1117,25 +1117,27 @@
       * @param propVal  The ORB.
       * @return the previous value of this property if any.
       */
+    @SuppressWarnings("unchecked")
     public java.lang.Object addToEnvironment(String propName,
         java.lang.Object propValue)
         throws NamingException {
             if (_env == null) {
-                _env = new Hashtable(7, 0.75f);
+                _env = new Hashtable<>(7, 0.75f);
             } else {
                 // copy-on-write
-                _env = (Hashtable)_env.clone();
+                _env = (Hashtable<String, java.lang.Object>)_env.clone();
             }
 
             return _env.put(propName, propValue);
     }
 
     // Record change but do not reinitialize ORB
+    @SuppressWarnings("unchecked")
     public java.lang.Object removeFromEnvironment(String propName)
         throws NamingException {
             if (_env != null  && _env.get(propName) != null) {
                 // copy-on-write
-                _env = (Hashtable)_env.clone();
+                _env = (Hashtable<String, java.lang.Object>)_env.clone();
                 return _env.remove(propName);
             }
             return null;
--- a/src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -67,7 +67,7 @@
     * @return a non-null CompoundName
     */
     public Name parse(String name) throws NamingException {
-        Vector comps = insStringToStringifiedComps(name);
+        Vector<String> comps = insStringToStringifiedComps(name);
         return new CNCompoundName(comps.elements());
     }
 
@@ -128,11 +128,11 @@
      * each element of the vector contains a stringified form of
      * a NameComponent.
      */
-    private static Vector insStringToStringifiedComps(String str)
+    private static Vector<String> insStringToStringifiedComps(String str)
         throws InvalidNameException {
 
         int len = str.length();
-        Vector components = new Vector(10);
+        Vector<String> components = new Vector<>(10);
         char[] id = new char[len];
         char[] kind = new char[len];
         int idCount, kindCount;
@@ -306,7 +306,7 @@
      * and stringifying code of the default CompoundName.
      */
     static final class CNCompoundName extends CompoundName {
-        CNCompoundName(Enumeration enum_) {
+        CNCompoundName(Enumeration<String> enum_) {
             super(enum_, CNNameParser.mySyntax);
         }
 
@@ -315,12 +315,12 @@
         }
 
         public Name getPrefix(int posn) {
-            Enumeration comps = super.getPrefix(posn).getAll();
+            Enumeration<String> comps = super.getPrefix(posn).getAll();
             return new CNCompoundName(comps);
         }
 
         public Name getSuffix(int posn) {
-            Enumeration comps = super.getSuffix(posn).getAll();
+            Enumeration<String> comps = super.getSuffix(posn).getAll();
             return new CNCompoundName(comps);
         }
 
--- a/src/share/classes/com/sun/jndi/cosnaming/ExceptionMapper.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/cosnaming/ExceptionMapper.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -104,10 +104,10 @@
 
     private static final NamingException tryFed(NotFound e, CNCtx ctx,
         NameComponent[] inputName) throws NamingException {
-        NameComponent[] rest = ((NotFound) e).rest_of_name;
+        NameComponent[] rest = e.rest_of_name;
 
         if (debug) {
-            System.out.println(((NotFound)e).why.value());
+            System.out.println(e.why.value());
             System.out.println(rest.length);
         }
 
--- a/src/share/classes/com/sun/jndi/cosnaming/IiopUrl.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/cosnaming/IiopUrl.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -68,7 +68,7 @@
     static final private int DEFAULT_IIOPNAME_PORT = 9999;
     static final private int DEFAULT_IIOP_PORT = 900;
     static final private String DEFAULT_HOST = "localhost";
-    private Vector addresses;
+    private Vector<Address> addresses;
     private String stringName;
 
     public static class Address {
@@ -149,7 +149,7 @@
         }
     }
 
-    public Vector getAddresses() {
+    public Vector<Address> getAddresses() {
         return addresses;
     }
 
@@ -185,7 +185,7 @@
         } else {
             stringName = UrlUtil.decode(url.substring(addrEnd+1));
         }
-        addresses = new Vector(3);
+        addresses = new Vector<>(3);
         if (oldFormat) {
             // Only one host:port part, not multiple
             addresses.addElement(
--- a/src/share/classes/com/sun/jndi/dns/DnsContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/dns/DnsContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -47,7 +47,7 @@
 
     DnsName domain;             // fully-qualified domain name of this context,
                                 // with a root (empty) label at position 0
-    Hashtable environment;
+    Hashtable<Object,Object> environment;
     private boolean envShared;  // true if environment is possibly shared
                                 // and so must be copied on write
     private boolean parentIsDns;        // was this DnsContext created by
@@ -95,14 +95,15 @@
      * There must be at least one server.
      * The environment must not be null; it is cloned before being stored.
      */
-    public DnsContext(String domain, String[] servers, Hashtable environment)
+    @SuppressWarnings("unchecked")
+    public DnsContext(String domain, String[] servers, Hashtable<?,?> environment)
             throws NamingException {
 
         this.domain = new DnsName(domain.endsWith(".")
                                   ? domain
                                   : domain + ".");
         this.servers = servers;
-        this.environment = (Hashtable) environment.clone();
+        this.environment = (Hashtable<Object,Object>) environment.clone();
         envShared = false;
         parentIsDns = false;
         resolver = null;
@@ -154,14 +155,15 @@
     /*
      * Override default with a noncloning version.
      */
-    protected Hashtable p_getEnvironment() {
+    protected Hashtable<?,?> p_getEnvironment() {
         return environment;
     }
 
-    public Hashtable getEnvironment() throws NamingException {
-        return (Hashtable) environment.clone();
+    public Hashtable<?,?> getEnvironment() throws NamingException {
+        return (Hashtable<?,?>) environment.clone();
     }
 
+    @SuppressWarnings("unchecked")
     public Object addToEnvironment(String propName, Object propVal)
             throws NamingException {
 
@@ -189,7 +191,7 @@
             return environment.put(propName, propVal);
         } else if (environment.get(propName) != propVal) {
             // copy on write
-            environment = (Hashtable) environment.clone();
+            environment = (Hashtable<Object,Object>) environment.clone();
             envShared = false;
             return environment.put(propName, propVal);
         } else {
@@ -197,6 +199,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     public Object removeFromEnvironment(String propName)
             throws NamingException {
 
@@ -222,7 +225,7 @@
             return environment.remove(propName);
         } else if (environment.get(propName) != null) {
             // copy-on-write
-            environment = (Hashtable) environment.clone();
+            environment = (Hashtable<Object,Object>) environment.clone();
             envShared = false;
             return environment.remove(propName);
         } else {
@@ -307,7 +310,7 @@
         return c_lookup(name, cont);
     }
 
-    public NamingEnumeration c_list(Name name, Continuation cont)
+    public NamingEnumeration<NameClassPair> c_list(Name name, Continuation cont)
             throws NamingException {
         cont.setSuccess();
         try {
@@ -322,7 +325,7 @@
         }
     }
 
-    public NamingEnumeration c_listBindings(Name name, Continuation cont)
+    public NamingEnumeration<Binding> c_listBindings(Name name, Continuation cont)
             throws NamingException {
         cont.setSuccess();
         try {
@@ -457,7 +460,7 @@
                 new OperationNotSupportedException());
     }
 
-    public NamingEnumeration c_search(Name name,
+    public NamingEnumeration<SearchResult> c_search(Name name,
                                       Attributes matchingAttributes,
                                       String[] attributesToReturn,
                                       Continuation cont)
@@ -465,7 +468,7 @@
         throw new OperationNotSupportedException();
     }
 
-    public NamingEnumeration c_search(Name name,
+    public NamingEnumeration<SearchResult> c_search(Name name,
                                       String filter,
                                       SearchControls cons,
                                       Continuation cont)
@@ -473,7 +476,7 @@
         throw new OperationNotSupportedException();
     }
 
-    public NamingEnumeration c_search(Name name,
+    public NamingEnumeration<SearchResult> c_search(Name name,
                                       String filterExpr,
                                       Object[] filterArgs,
                                       SearchControls cons,
@@ -608,7 +611,7 @@
         BasicAttributes attrs = new BasicAttributes(true);
 
         for (int i = 0; i < rrs.answer.size(); i++) {
-            ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i);
+            ResourceRecord rr = rrs.answer.elementAt(i);
             int rrtype  = rr.getType();
             int rrclass = rr.getRrclass();
 
@@ -952,19 +955,14 @@
 //----------
 
 /*
- * An enumeration of name/classname pairs.
- *
- * Nodes that have children or that are zone cuts are returned with
- * classname DirContext.  Other nodes are returned with classname
- * Object even though they are DirContexts as well, since this might
- * make the namespace easier to browse.
+ * Common base class for NameClassPairEnumeration and BindingEnumeration.
  */
-class NameClassPairEnumeration implements NamingEnumeration {
+abstract class BaseNameClassPairEnumeration<T> implements NamingEnumeration<T> {
 
-    protected Enumeration nodes;    // nodes to be enumerated, or null if none
+    protected Enumeration<NameNode> nodes;    // nodes to be enumerated, or null if none
     protected DnsContext ctx;       // context being enumerated
 
-    NameClassPairEnumeration(DnsContext ctx, Hashtable nodes) {
+    BaseNameClassPairEnumeration(DnsContext ctx, Hashtable<String,NameNode> nodes) {
         this.ctx = ctx;
         this.nodes = (nodes != null)
             ? nodes.elements()
@@ -974,12 +972,12 @@
     /*
      * ctx will be set to null when no longer needed by the enumeration.
      */
-    public void close() {
+    public final void close() {
         nodes = null;
         ctx = null;
     }
 
-    public boolean hasMore() {
+    public final boolean hasMore() {
         boolean more = ((nodes != null) && nodes.hasMoreElements());
         if (!more) {
             close();
@@ -987,11 +985,46 @@
         return more;
     }
 
-    public Object next() throws NamingException {
+    public final boolean hasMoreElements() {
+        return hasMore();
+    }
+
+    abstract public T next() throws NamingException;
+
+    public final T nextElement() {
+        try {
+            return next();
+        } catch (NamingException e) {
+            java.util.NoSuchElementException nsee =
+                    new java.util.NoSuchElementException();
+            nsee.initCause(e);
+            throw nsee;
+        }
+    }
+}
+
+/*
+ * An enumeration of name/classname pairs.
+ *
+ * Nodes that have children or that are zone cuts are returned with
+ * classname DirContext.  Other nodes are returned with classname
+ * Object even though they are DirContexts as well, since this might
+ * make the namespace easier to browse.
+ */
+final class NameClassPairEnumeration
+        extends BaseNameClassPairEnumeration<NameClassPair>
+        implements NamingEnumeration<NameClassPair> {
+
+    NameClassPairEnumeration(DnsContext ctx, Hashtable<String,NameNode> nodes) {
+        super(ctx, nodes);
+    }
+
+    @Override
+    public NameClassPair next() throws NamingException {
         if (!hasMore()) {
             throw new java.util.NoSuchElementException();
         }
-        NameNode nnode = (NameNode) nodes.nextElement();
+        NameNode nnode = nodes.nextElement();
         String className = (nnode.isZoneCut() ||
                             (nnode.getChildren() != null))
             ? "javax.naming.directory.DirContext"
@@ -1005,28 +1038,15 @@
         ncp.setNameInNamespace(ctx.fullyQualify(cname).toString());
         return ncp;
     }
-
-    public boolean hasMoreElements() {
-        return hasMore();
-    }
-
-    public Object nextElement() {
-        try {
-            return next();
-        } catch (NamingException e) {
-            throw (new java.util.NoSuchElementException(
-                    "javax.naming.NamingException was thrown: " +
-                    e.getMessage()));
-        }
-    }
 }
 
 /*
  * An enumeration of Bindings.
  */
-class BindingEnumeration extends NameClassPairEnumeration {
+final class BindingEnumeration extends BaseNameClassPairEnumeration<Binding>
+                         implements NamingEnumeration<Binding> {
 
-    BindingEnumeration(DnsContext ctx, Hashtable nodes) {
+    BindingEnumeration(DnsContext ctx, Hashtable<String,NameNode> nodes) {
         super(ctx, nodes);
     }
 
@@ -1035,11 +1055,12 @@
 //      close();
 //  }
 
-    public Object next() throws NamingException {
+    @Override
+    public Binding next() throws NamingException {
         if (!hasMore()) {
             throw (new java.util.NoSuchElementException());
         }
-        NameNode nnode = (NameNode) nodes.nextElement();
+        NameNode nnode = nodes.nextElement();
 
         String label = nnode.getLabel();
         Name compName = (new DnsName()).add(label);
--- a/src/share/classes/com/sun/jndi/dns/DnsContextFactory.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/dns/DnsContextFactory.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -59,7 +59,7 @@
 
     public Context getInitialContext(Hashtable<?,?> env) throws NamingException {
         if (env == null) {
-            env = new Hashtable(5);
+            env = new Hashtable<>(5);
         }
         return urlToContext(getInitCtxUrl(env), env);
     }
@@ -75,7 +75,7 @@
      * components are overridden by "domain".
      */
     public static DnsContext getContext(String domain,
-                                        DnsUrl[] urls, Hashtable env)
+                                        DnsUrl[] urls, Hashtable<?,?> env)
             throws NamingException {
 
         String[] servers = serversForUrls(urls);
@@ -95,7 +95,7 @@
                 ).isEmpty();
     }
 
-    private static Context urlToContext(String url, Hashtable env)
+    private static Context urlToContext(String url, Hashtable<?,?> env)
             throws NamingException {
 
         DnsUrl[] urls;
@@ -212,7 +212,7 @@
      * Reads environment to find URL(s) of initial context.
      * Default URL is "dns:".
      */
-    private static String getInitCtxUrl(Hashtable env) {
+    private static String getInitCtxUrl(Hashtable<?,?> env) {
         String url = (String) env.get(Context.PROVIDER_URL);
         return ((url != null) ? url : DEFAULT_URL);
     }
@@ -223,34 +223,31 @@
      * @param oneIsEnough return output once there exists one ok
      * @return the filtered list, all non-permitted input removed
      */
-    private static List filterNameServers(List input, boolean oneIsEnough) {
+    private static List<String> filterNameServers(List<String> input, boolean oneIsEnough) {
         SecurityManager security = System.getSecurityManager();
         if (security == null || input == null || input.isEmpty()) {
             return input;
         } else {
-            List output = new ArrayList();
-            for (Object o: input) {
-                if (o instanceof String) {
-                    String platformServer = (String)o;
-                    int colon = platformServer.indexOf(':',
-                            platformServer.indexOf(']') + 1);
+            List<String> output = new ArrayList<>();
+            for (String platformServer: input) {
+                int colon = platformServer.indexOf(':',
+                        platformServer.indexOf(']') + 1);
 
-                    int p = (colon < 0)
-                        ? DEFAULT_PORT
-                        : Integer.parseInt(
-                            platformServer.substring(colon + 1));
-                    String s = (colon < 0)
-                        ? platformServer
-                        : platformServer.substring(0, colon);
-                    try {
-                        security.checkConnect(s, p);
-                        output.add(platformServer);
-                        if (oneIsEnough) {
-                            return output;
-                        }
-                    } catch (SecurityException se) {
-                        continue;
+                int p = (colon < 0)
+                    ? DEFAULT_PORT
+                    : Integer.parseInt(
+                        platformServer.substring(colon + 1));
+                String s = (colon < 0)
+                    ? platformServer
+                    : platformServer.substring(0, colon);
+                try {
+                    security.checkConnect(s, p);
+                    output.add(platformServer);
+                    if (oneIsEnough) {
+                        return output;
                     }
+                } catch (SecurityException se) {
+                    continue;
                 }
             }
             return output;
--- a/src/share/classes/com/sun/jndi/dns/DnsName.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/dns/DnsName.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,6 @@
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Enumeration;
-import java.util.Iterator;
 
 import javax.naming.*;
 
@@ -111,7 +110,7 @@
     // The labels of this domain name, as a list of strings.  Index 0
     // corresponds to the leftmost (least significant) label:  note that
     // this is the reverse of the ordering used by the Name interface.
-    private ArrayList labels = new ArrayList();
+    private ArrayList<String> labels = new ArrayList<>();
 
     // The number of octets needed to carry this domain name in a DNS
     // packet.  Equal to the sum of the lengths of each label, plus the
@@ -152,9 +151,7 @@
             domain = n.domain;
             octets = n.octets;
         } else {
-            Iterator iter = labels.iterator();
-            while (iter.hasNext()) {
-                String label = (String) iter.next();
+            for (String label: labels) {
                 if (label.length() > 0) {
                     octets += (short) (label.length() + 1);
                 }
@@ -165,10 +162,8 @@
 
     public String toString() {
         if (domain == null) {
-            StringBuffer buf = new StringBuffer();
-            Iterator iter = labels.iterator();
-            while (iter.hasNext()) {
-                String label = (String) iter.next();
+            StringBuilder buf = new StringBuilder();
+            for (String label: labels) {
                 if (buf.length() > 0 || label.length() == 0) {
                     buf.append('.');
                 }
@@ -183,9 +178,8 @@
      * Does this domain name follow <em>host name</em> syntax?
      */
     public boolean isHostName() {
-        Iterator iter = labels.iterator();
-        while (iter.hasNext()) {
-            if (!isHostNameLabel((String) iter.next())) {
+        for (String label: labels) {
+            if (!isHostNameLabel(label)) {
                 return false;
             }
         }
@@ -241,16 +235,16 @@
             throw new ArrayIndexOutOfBoundsException();
         }
         int i = size() - pos - 1;       // index of "pos" component in "labels"
-        return (String) labels.get(i);
+        return labels.get(i);
     }
 
-    public Enumeration getAll() {
-        return new Enumeration() {
+    public Enumeration<String> getAll() {
+        return new Enumeration<String>() {
             int pos = 0;
             public boolean hasMoreElements() {
                 return (pos < size());
             }
-            public Object nextElement() {
+            public String nextElement() {
                 if (pos < size()) {
                     return get(pos++);
                 }
@@ -276,7 +270,7 @@
             throw new ArrayIndexOutOfBoundsException();
         }
         int i = size() - pos - 1;     // index of element to remove in "labels"
-        String label = (String) labels.remove(i);
+        String label = labels.remove(i);
         int len = label.length();
         if (len > 0) {
             octets -= (short) (len + 1);
@@ -530,7 +524,7 @@
     /*
      * Append a label to buf, escaping as needed.
      */
-    private static void escape(StringBuffer buf, String label) {
+    private static void escape(StringBuilder buf, String label) {
         for (int i = 0; i < label.length(); i++) {
             char c = label.charAt(i);
             if (c == '.' || c == '\\') {
--- a/src/share/classes/com/sun/jndi/dns/NameNode.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/dns/NameNode.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -52,7 +52,7 @@
 
     private String label;               // name of this node relative to its
                                         // parent, or null for root of a tree
-    private Hashtable children = null;  // child nodes
+    private Hashtable<String,NameNode> children = null;  // child nodes
     private boolean isZoneCut = false;  // true if this node is a zone cut
     private int depth = 0;              // depth in tree (0 for root)
 
@@ -97,7 +97,7 @@
      * Returns the children of this node, or null if there are none.
      * The caller must not modify the Hashtable returned.
      */
-    Hashtable getChildren() {
+    Hashtable<String,NameNode> getChildren() {
         return children;
     }
 
@@ -108,7 +108,7 @@
      */
     NameNode get(String key) {
         return (children != null)
-            ? (NameNode) children.get(key)
+            ? children.get(key)
             : null;
     }
 
@@ -140,9 +140,9 @@
 
             NameNode child = null;
             if (node.children == null) {
-                node.children = new Hashtable();
+                node.children = new Hashtable<>();
             } else {
-                child = (NameNode) node.children.get(key);
+                child = node.children.get(key);
             }
             if (child == null) {
                 child = newNameNode(label);
--- a/src/share/classes/com/sun/jndi/dns/Resolver.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/dns/Resolver.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -125,8 +125,7 @@
                 }
                 // Look for an SOA record giving the zone's top node.
                 for (int i = 0; i < rrs.authority.size(); i++) {
-                    ResourceRecord rr = (ResourceRecord)
-                        rrs.authority.elementAt(i);
+                    ResourceRecord rr = rrs.authority.elementAt(i);
                     if (rr.getType() == ResourceRecord.TYPE_SOA) {
                         DnsName zone = rr.getName();
                         if (fqdn.endsWith(zone)) {
@@ -152,7 +151,7 @@
         ResourceRecords rrs = query(zone, rrclass, ResourceRecord.TYPE_SOA,
                                     recursion, false);
         for (int i = 0; i < rrs.answer.size(); i++) {
-            ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i);
+            ResourceRecord rr = rrs.answer.elementAt(i);
             if (rr.getType() == ResourceRecord.TYPE_SOA) {
                 return rr;
             }
@@ -175,8 +174,7 @@
                   recursion, false);
         String[] ns = new String[rrs.answer.size()];
         for (int i = 0; i < ns.length; i++) {
-            ResourceRecord rr = (ResourceRecord)
-                rrs.answer.elementAt(i);
+            ResourceRecord rr = rrs.answer.elementAt(i);
             if (rr.getType() != ResourceRecord.TYPE_NS) {
                 throw new CommunicationException("Corrupted DNS message");
             }
--- a/src/share/classes/com/sun/jndi/dns/ResourceRecords.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/dns/ResourceRecords.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,10 +45,10 @@
     // Four sections:  question, answer, authority, additional.
     // The question section is treated as being made up of (shortened)
     // resource records, although this isn't technically how it's defined.
-    Vector question = new Vector();
-    Vector answer = new Vector();
-    Vector authority = new Vector();
-    Vector additional = new Vector();
+    Vector<ResourceRecord> question = new Vector<>();
+    Vector<ResourceRecord> answer = new Vector<>();
+    Vector<ResourceRecord> authority = new Vector<>();
+    Vector<ResourceRecord> additional = new Vector<>();
 
     /*
      * True if these resource records are from a zone transfer.  In
@@ -80,7 +80,7 @@
         if (answer.size() == 0) {
             return -1;
         }
-        return ((ResourceRecord) answer.firstElement()).getType();
+        return answer.firstElement().getType();
     }
 
     /*
@@ -91,7 +91,7 @@
         if (answer.size() == 0) {
             return -1;
         }
-        return ((ResourceRecord) answer.lastElement()).getType();
+        return answer.lastElement().getType();
     }
 
     /*
--- a/src/share/classes/com/sun/jndi/dns/ZoneNode.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/dns/ZoneNode.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,7 +55,7 @@
 
 class ZoneNode extends NameNode {
 
-    private SoftReference contentsRef = null;   // the zone's namespace
+    private SoftReference<NameNode> contentsRef = null;   // the zone's namespace
     private long serialNumber = -1;     // the zone data's serial number
     private Date expiration = null;     // time when the zone's data expires
 
@@ -88,7 +88,7 @@
      */
     synchronized NameNode getContents() {
         return (contentsRef != null)
-                ? (NameNode) contentsRef.get()
+                ? contentsRef.get()
                 : null;
     }
 
@@ -130,7 +130,7 @@
         NameNode newContents = new NameNode(null);
 
         for (int i = 0; i < rrs.answer.size(); i++) {
-            ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i);
+            ResourceRecord rr = rrs.answer.elementAt(i);
             DnsName n = rr.getName();
 
             // Ignore resource records whose names aren't within the zone's
@@ -144,9 +144,9 @@
             }
         }
         // The zone's SOA record is the first record in the answer section.
-        ResourceRecord soa = (ResourceRecord) rrs.answer.firstElement();
+        ResourceRecord soa = rrs.answer.firstElement();
         synchronized (this) {
-            contentsRef = new SoftReference(newContents);
+            contentsRef = new SoftReference<NameNode>(newContents);
             serialNumber = getSerialNumber(soa);
             setExpiration(getMinimumTtl(soa));
             return newContents;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/AbstractLdapNamingEnumeration.java	Mon Jan 30 08:02:44 2017 +0000
@@ -0,0 +1,408 @@
+/*
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.jndi.ldap;
+
+import com.sun.jndi.toolkit.ctx.Continuation;
+import java.util.NoSuchElementException;
+import java.util.Vector;
+
+import javax.naming.*;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.Control;
+
+/**
+ * Basic enumeration for NameClassPair, Binding, and SearchResults.
+ */
+
+abstract class AbstractLdapNamingEnumeration<T extends NameClassPair>
+        implements NamingEnumeration<T>, ReferralEnumeration<T> {
+
+    protected Name listArg;
+
+    private boolean cleaned = false;
+    private LdapResult res;
+    private LdapClient enumClnt;
+    private Continuation cont;  // used to fill in exceptions
+    private Vector<LdapEntry> entries = null;
+    private int limit = 0;
+    private int posn = 0;
+    protected LdapCtx homeCtx;
+    private LdapReferralException refEx = null;
+    private NamingException errEx = null;
+
+    /*
+     * Record the next set of entries and/or referrals.
+     */
+    AbstractLdapNamingEnumeration(LdapCtx homeCtx, LdapResult answer, Name listArg,
+        Continuation cont) throws NamingException {
+
+            // These checks are to accommodate referrals and limit exceptions
+            // which will generate an enumeration and defer the exception
+            // to be thrown at the end of the enumeration.
+            // All other exceptions are thrown immediately.
+            // Exceptions shouldn't be thrown here anyhow because
+            // process_return_code() is called before the constructor
+            // is called, so these are just safety checks.
+
+            if ((answer.status != LdapClient.LDAP_SUCCESS) &&
+                (answer.status != LdapClient.LDAP_SIZE_LIMIT_EXCEEDED) &&
+                (answer.status != LdapClient.LDAP_TIME_LIMIT_EXCEEDED) &&
+                (answer.status != LdapClient.LDAP_ADMIN_LIMIT_EXCEEDED) &&
+                (answer.status != LdapClient.LDAP_REFERRAL) &&
+                (answer.status != LdapClient.LDAP_PARTIAL_RESULTS)) {
+
+                // %%% need to deal with referral
+                NamingException e = new NamingException(
+                                    LdapClient.getErrorMessage(
+                                    answer.status, answer.errorMessage));
+
+                throw cont.fillInException(e);
+            }
+
+            // otherwise continue
+
+            res = answer;
+            entries = answer.entries;
+            limit = (entries == null) ? 0 : entries.size(); // handle empty set
+            this.listArg = listArg;
+            this.cont = cont;
+
+            if (answer.refEx != null) {
+                refEx = answer.refEx;
+            }
+
+            // Ensures that context won't get closed from underneath us
+            this.homeCtx = homeCtx;
+            homeCtx.incEnumCount();
+            enumClnt = homeCtx.clnt; // remember
+    }
+
+    @Override
+    public final T nextElement() {
+        try {
+            return next();
+        } catch (NamingException e) {
+            // can't throw exception
+            cleanup();
+            return null;
+        }
+    }
+
+    @Override
+    public final boolean hasMoreElements() {
+        try {
+            return hasMore();
+        } catch (NamingException e) {
+            // can't throw exception
+            cleanup();
+            return false;
+        }
+    }
+
+    /*
+     * Retrieve the next set of entries and/or referrals.
+     */
+    private void getNextBatch() throws NamingException {
+
+        res = homeCtx.getSearchReply(enumClnt, res);
+        if (res == null) {
+            limit = posn = 0;
+            return;
+        }
+
+        entries = res.entries;
+        limit = (entries == null) ? 0 : entries.size(); // handle empty set
+        posn = 0; // reset
+
+        // mimimize the number of calls to processReturnCode()
+        // (expensive when batchSize is small and there are many results)
+        if ((res.status != LdapClient.LDAP_SUCCESS) ||
+            ((res.status == LdapClient.LDAP_SUCCESS) &&
+                (res.referrals != null))) {
+
+            try {
+                // convert referrals into a chain of LdapReferralException
+                homeCtx.processReturnCode(res, listArg);
+
+            } catch (LimitExceededException | PartialResultException e) {
+                setNamingException(e);
+
+            }
+        }
+
+        // merge any newly received referrals with any current referrals
+        if (res.refEx != null) {
+            if (refEx == null) {
+                refEx = res.refEx;
+            } else {
+                refEx = refEx.appendUnprocessedReferrals(res.refEx);
+            }
+            res.refEx = null; // reset
+        }
+
+        if (res.resControls != null) {
+            homeCtx.respCtls = res.resControls;
+        }
+    }
+
+    private boolean more = true;  // assume we have something to start with
+    private boolean hasMoreCalled = false;
+
+    /*
+     * Test if unprocessed entries or referrals exist.
+     */
+    @Override
+    public final boolean hasMore() throws NamingException {
+
+        if (hasMoreCalled) {
+            return more;
+        }
+
+        hasMoreCalled = true;
+
+        if (!more) {
+            return false;
+        } else {
+            return (more = hasMoreImpl());
+        }
+    }
+
+    /*
+     * Retrieve the next entry.
+     */
+    @Override
+    public final T next() throws NamingException {
+
+        if (!hasMoreCalled) {
+            hasMore();
+        }
+        hasMoreCalled = false;
+        return nextImpl();
+    }
+
+    /*
+     * Test if unprocessed entries or referrals exist.
+     */
+    private boolean hasMoreImpl() throws NamingException {
+        // when page size is supported, this
+        // might generate an exception while attempting
+        // to fetch the next batch to determine
+        // whether there are any more elements
+
+        // test if the current set of entries has been processed
+        if (posn == limit) {
+            getNextBatch();
+        }
+
+        // test if any unprocessed entries exist
+        if (posn < limit) {
+            return true;
+        } else {
+
+            try {
+                // try to process another referral
+                return hasMoreReferrals();
+
+            } catch (LdapReferralException |
+                     LimitExceededException |
+                     PartialResultException e) {
+                cleanup();
+                throw e;
+
+            } catch (NamingException e) {
+                cleanup();
+                PartialResultException pre = new PartialResultException();
+                pre.setRootCause(e);
+                throw pre;
+            }
+        }
+    }
+
+    /*
+     * Retrieve the next entry.
+     */
+    private T nextImpl() throws NamingException {
+        try {
+            return nextAux();
+        } catch (NamingException e) {
+            cleanup();
+            throw cont.fillInException(e);
+        }
+    }
+
+    private T nextAux() throws NamingException {
+        if (posn == limit) {
+            getNextBatch();  // updates posn and limit
+        }
+
+        if (posn >= limit) {
+            cleanup();
+            throw new NoSuchElementException("invalid enumeration handle");
+        }
+
+        LdapEntry result = entries.elementAt(posn++);
+
+        // gets and outputs DN from the entry
+        return createItem(result.DN, result.attributes, result.respCtls);
+    }
+
+    protected final String getAtom(String dn) {
+        // need to strip off all but lowest component of dn
+        // so that is relative to current context (currentDN)
+        try {
+            Name parsed = new LdapName(dn);
+            return parsed.get(parsed.size() - 1);
+        } catch (NamingException e) {
+            return dn;
+        }
+    }
+
+    protected abstract T createItem(String dn, Attributes attrs,
+        Vector<Control> respCtls) throws NamingException;
+
+    /*
+     * Append the supplied (chain of) referrals onto the
+     * end of the current (chain of) referrals.
+     */
+    @Override
+    public void appendUnprocessedReferrals(LdapReferralException ex) {
+        if (refEx != null) {
+            refEx = refEx.appendUnprocessedReferrals(ex);
+        } else {
+            refEx = ex.appendUnprocessedReferrals(refEx);
+        }
+    }
+
+    final void setNamingException(NamingException e) {
+        errEx = e;
+    }
+
+    protected abstract AbstractLdapNamingEnumeration<T> getReferredResults(
+            LdapReferralContext refCtx) throws NamingException;
+
+    /*
+     * Iterate through the URLs of a referral. If successful then perform
+     * a search operation and merge the received results with the current
+     * results.
+     */
+    protected final boolean hasMoreReferrals() throws NamingException {
+
+        if ((refEx != null) &&
+            (refEx.hasMoreReferrals() ||
+             refEx.hasMoreReferralExceptions())) {
+
+            if (homeCtx.handleReferrals == LdapClient.LDAP_REF_THROW) {
+                throw (NamingException)(refEx.fillInStackTrace());
+            }
+
+            // process the referrals sequentially
+            while (true) {
+
+                LdapReferralContext refCtx =
+                    (LdapReferralContext)refEx.getReferralContext(
+                    homeCtx.envprops, homeCtx.reqCtls);
+
+                try {
+
+                    update(getReferredResults(refCtx));
+                    break;
+
+                } catch (LdapReferralException re) {
+
+                    // record a previous exception
+                    if (errEx == null) {
+                        errEx = re.getNamingException();
+                    }
+                    refEx = re;
+                    continue;
+
+                } finally {
+                    // Make sure we close referral context
+                    refCtx.close();
+                }
+            }
+            return hasMoreImpl();
+
+        } else {
+            cleanup();
+
+            if (errEx != null) {
+                throw errEx;
+            }
+            return (false);
+        }
+    }
+
+    /*
+     * Merge the entries and/or referrals from the supplied enumeration
+     * with those of the current enumeration.
+     */
+    protected void update(AbstractLdapNamingEnumeration<T> ne) {
+        // Cleanup previous context first
+        homeCtx.decEnumCount();
+
+        // New enum will have already incremented enum count and recorded clnt
+        homeCtx = ne.homeCtx;
+        enumClnt = ne.enumClnt;
+
+        // Do this to prevent referral enumeration (ne) from decrementing
+        // enum count because we'll be doing that here from this
+        // enumeration.
+        ne.homeCtx = null;
+
+        // Record rest of information from new enum
+        posn = ne.posn;
+        limit = ne.limit;
+        res = ne.res;
+        entries = ne.entries;
+        refEx = ne.refEx;
+        listArg = ne.listArg;
+    }
+
+    protected final void finalize() {
+        cleanup();
+    }
+
+    protected final void cleanup() {
+        if (cleaned) return; // been there; done that
+
+        if(enumClnt != null) {
+            enumClnt.clearSearchReply(res, homeCtx.reqCtls);
+        }
+
+        enumClnt = null;
+        cleaned = true;
+        if (homeCtx != null) {
+            homeCtx.decEnumCount();
+            homeCtx = null;
+        }
+    }
+
+    @Override
+    public final void close() {
+        cleanup();
+    }
+}
--- a/src/share/classes/com/sun/jndi/ldap/Ber.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/Ber.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -94,12 +94,14 @@
     public static final int ASN_ENUMERATED      = 0x0a;
 
     final static class EncodeException extends IOException {
+        private static final long serialVersionUID = -5247359637775781768L;
         EncodeException(String msg) {
             super(msg);
         }
     }
 
     final static class DecodeException extends IOException {
+        private static final long serialVersionUID = 8735036969244425583L;
         DecodeException(String msg) {
             super(msg);
         }
--- a/src/share/classes/com/sun/jndi/ldap/ClientId.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/ClientId.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -74,7 +74,7 @@
         this.hostname = hostname.toLowerCase();  // ignore case
         this.port = port;
         this.protocol = protocol;
-        this.bindCtls = (bindCtls != null ? (Control[]) bindCtls.clone() : null);
+        this.bindCtls = (bindCtls != null ? bindCtls.clone() : null);
         this.trace = trace;
         //
         // Needed for custom socket factory pooling
@@ -83,12 +83,12 @@
         if ((socketFactory != null) &&
              !socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) {
             try {
-                Class socketFactoryClass = Obj.helper.loadClass(socketFactory);
-                Class objClass = Class.forName("java.lang.Object");
+                Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory);
+                Class<?> objClass = Class.forName("java.lang.Object");
                 this.sockComparator = socketFactoryClass.getMethod(
-                                "compare", new Class[]{objClass, objClass});
+                                "compare", new Class<?>[]{objClass, objClass});
                 Method getDefault =
-                    socketFactoryClass.getMethod("getDefault", new Class[]{});
+                    socketFactoryClass.getMethod("getDefault", new Class<?>[]{});
                 this.factory = (SocketFactory) getDefault.invoke(null, new Object[]{});
             } catch (Exception e) {
                 // Ignore it here, the same exceptions are/will be handled by
--- a/src/share/classes/com/sun/jndi/ldap/Connection.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/Connection.java	Mon Jan 30 08:02:44 2017 +0000
@@ -241,27 +241,22 @@
             throws NoSuchMethodException {
 
         try {
-            Class inetSocketAddressClass =
+            Class<?> inetSocketAddressClass =
                 Class.forName("java.net.InetSocketAddress");
 
-            Constructor inetSocketAddressCons =
-                inetSocketAddressClass.getConstructor(new Class[]{
+            Constructor<?> inetSocketAddressCons =
+                inetSocketAddressClass.getConstructor(new Class<?>[]{
                 String.class, int.class});
 
             return inetSocketAddressCons.newInstance(new Object[]{
                 host, new Integer(port)});
 
-        } catch (ClassNotFoundException e) {
+        } catch (ClassNotFoundException |
+                 InstantiationException |
+                 InvocationTargetException |
+                 IllegalAccessException e) {
             throw new NoSuchMethodException();
 
-        } catch (InstantiationException e) {
-            throw new NoSuchMethodException();
-
-        } catch (InvocationTargetException e) {
-            throw new NoSuchMethodException();
-
-        } catch (IllegalAccessException e) {
-            throw new NoSuchMethodException();
         }
     }
 
@@ -283,9 +278,9 @@
 
             // create the factory
 
-            Class socketFactoryClass = Obj.helper.loadClass(socketFactory);
+            Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory);
             Method getDefault =
-                socketFactoryClass.getMethod("getDefault", new Class[]{});
+                socketFactoryClass.getMethod("getDefault", new Class<?>[]{});
             Object factory = getDefault.invoke(null, new Object[]{});
 
             // create the socket
@@ -296,10 +291,10 @@
 
                 try {
                     createSocket = socketFactoryClass.getMethod("createSocket",
-                        new Class[]{});
+                        new Class<?>[]{});
 
                     Method connect = Socket.class.getMethod("connect",
-                        new Class[]{Class.forName("java.net.SocketAddress"),
+                        new Class<?>[]{Class.forName("java.net.SocketAddress"),
                         int.class});
                     Object endpoint = createInetSocketAddress(host, port);
 
@@ -323,7 +318,7 @@
 
             if (socket == null) {
                 createSocket = socketFactoryClass.getMethod("createSocket",
-                    new Class[]{String.class, int.class});
+                    new Class<?>[]{String.class, int.class});
 
                 if (debug) {
                     System.err.println("Connection: creating socket using " +
@@ -338,15 +333,15 @@
             if (connectTimeout > 0) {
 
                 try {
-                    Constructor socketCons =
-                        Socket.class.getConstructor(new Class[]{});
+                    Constructor<Socket> socketCons =
+                        Socket.class.getConstructor(new Class<?>[]{});
 
                     Method connect = Socket.class.getMethod("connect",
-                        new Class[]{Class.forName("java.net.SocketAddress"),
+                        new Class<?>[]{Class.forName("java.net.SocketAddress"),
                         int.class});
                     Object endpoint = createInetSocketAddress(host, port);
 
-                    socket = (Socket) socketCons.newInstance(new Object[]{});
+                    socket = socketCons.newInstance(new Object[]{});
 
                     if (debug) {
                         System.err.println("Connection: creating socket with " +
--- a/src/share/classes/com/sun/jndi/ldap/DigestClientId.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/DigestClientId.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -65,7 +65,7 @@
     DigestClientId(int version, String hostname, int port,
         String protocol, Control[] bindCtls, OutputStream trace,
         String socketFactory, String username,
-        Object passwd, Hashtable env) {
+        Object passwd, Hashtable<?,?> env) {
 
         super(version, hostname, port, protocol, bindCtls, trace,
             socketFactory, username, passwd);
--- a/src/share/classes/com/sun/jndi/ldap/EventQueue.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/EventQueue.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
 
 package com.sun.jndi.ldap;
 
-import java.io.*;
 import java.util.Vector;
 import java.util.EventObject;
 
@@ -52,9 +51,9 @@
         QueueElement next = null;
         QueueElement prev = null;
         EventObject event = null;
-        Vector vector = null;
+        Vector<NamingListener> vector = null;
 
-        QueueElement(EventObject event, Vector vector) {
+        QueueElement(EventObject event, Vector<NamingListener> vector) {
             this.event = event;
             this.vector = vector;
         }
@@ -87,7 +86,7 @@
      * are notified.
      * @param vector List of NamingListeners that will be notified of event.
      */
-    synchronized void enqueue(EventObject event, Vector vector) {
+    synchronized void enqueue(EventObject event, Vector<NamingListener> vector) {
         QueueElement newElt = new QueueElement(event, vector);
 
         if (head == null) {
@@ -133,7 +132,7 @@
         try {
             while ((qe = dequeue()) != null) {
                 EventObject e = qe.event;
-                Vector v = qe.vector;
+                Vector<NamingListener> v = qe.vector;
 
                 for (int i = 0; i < v.size(); i++) {
 
@@ -145,12 +144,11 @@
                     // only enqueue events with listseners of the correct type.
 
                     if (e instanceof NamingEvent) {
-                        ((NamingEvent)e).dispatch((NamingListener)v.elementAt(i));
+                        ((NamingEvent)e).dispatch(v.elementAt(i));
 
                     // An exception occurred: if notify all naming listeners
                     } else if (e instanceof NamingExceptionEvent) {
-                        ((NamingExceptionEvent)e).dispatch(
-                            (NamingListener)v.elementAt(i));
+                        ((NamingExceptionEvent)e).dispatch(v.elementAt(i));
                     } else if (e instanceof UnsolicitedNotificationEvent) {
                         ((UnsolicitedNotificationEvent)e).dispatch(
                             (UnsolicitedNotificationListener)v.elementAt(i));
--- a/src/share/classes/com/sun/jndi/ldap/EventSupport.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/EventSupport.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,11 +27,9 @@
 
 import java.util.Hashtable;
 import java.util.Vector;
-import java.util.Enumeration;
 import java.util.EventObject;
 
 import javax.naming.*;
-import javax.naming.directory.*;
 import javax.naming.event.*;
 import javax.naming.directory.SearchControls;
 import javax.naming.ldap.UnsolicitedNotificationListener;
@@ -120,12 +118,13 @@
     /**
      * NamingEventNotifiers; hashed by search arguments;
      */
-    private Hashtable notifiers = new Hashtable(11);
+    private Hashtable<NotifierArgs, NamingEventNotifier> notifiers =
+            new Hashtable<>(11);
 
     /**
      * List of unsolicited notification listeners.
      */
-    private Vector unsolicited = null;
+    private Vector<UnsolicitedNotificationListener> unsolicited = null;
 
     /**
      * Constructs EventSupport for ctx.
@@ -155,8 +154,7 @@
             l instanceof NamespaceChangeListener) {
             NotifierArgs args = new NotifierArgs(nm, scope, l);
 
-            NamingEventNotifier notifier =
-                (NamingEventNotifier) notifiers.get(args);
+            NamingEventNotifier notifier = notifiers.get(args);
             if (notifier == null) {
                 notifier = new NamingEventNotifier(this, ctx, args, l);
                 notifiers.put(args, notifier);
@@ -167,10 +165,10 @@
         if (l instanceof UnsolicitedNotificationListener) {
             // Add listener to this's list of unsolicited notifiers
             if (unsolicited == null) {
-                unsolicited = new Vector(3);
+                unsolicited = new Vector<>(3);
             }
 
-            unsolicited.addElement(l);
+            unsolicited.addElement((UnsolicitedNotificationListener)l);
         }
     }
 
@@ -185,8 +183,7 @@
             l instanceof NamespaceChangeListener) {
             NotifierArgs args = new NotifierArgs(nm, filter, ctls, l);
 
-            NamingEventNotifier notifier =
-                (NamingEventNotifier) notifiers.get(args);
+            NamingEventNotifier notifier = notifiers.get(args);
             if (notifier == null) {
                 notifier = new NamingEventNotifier(this, ctx, args, l);
                 notifiers.put(args, notifier);
@@ -197,9 +194,9 @@
         if (l instanceof UnsolicitedNotificationListener) {
             // Add listener to this's list of unsolicited notifiers
             if (unsolicited == null) {
-                unsolicited = new Vector(3);
+                unsolicited = new Vector<>(3);
             }
-            unsolicited.addElement(l);
+            unsolicited.addElement((UnsolicitedNotificationListener)l);
         }
     }
 
@@ -207,15 +204,11 @@
      * Removes <tt>l</tt> from all notifiers in this context.
      */
     synchronized void removeNamingListener(NamingListener l) {
-        Enumeration allnotifiers = notifiers.elements();
-        NamingEventNotifier notifier;
-
         if (debug) System.err.println("EventSupport removing listener");
 
         // Go through list of notifiers, remove 'l' from each.
         // If 'l' is notifier's only listener, remove notifier too.
-        while (allnotifiers.hasMoreElements()) {
-            notifier = (NamingEventNotifier)allnotifiers.nextElement();
+        for (NamingEventNotifier notifier : notifiers.values()) {
             if (notifier != null) {
                 if (debug)
                     System.err.println("EventSupport removing listener from notifier");
@@ -305,8 +298,8 @@
     synchronized void cleanup() {
         if (debug) System.err.println("EventSupport clean up");
         if (notifiers != null) {
-            for (Enumeration ns = notifiers.elements(); ns.hasMoreElements(); ) {
-                ((NamingEventNotifier) ns.nextElement()).stop();
+            for (NamingEventNotifier notifier : notifiers.values()) {
+                notifier.stop();
             }
             notifiers = null;
         }
@@ -328,7 +321,8 @@
      * them to the registered listeners.
      * Package private; used by NamingEventNotifier to fire events
      */
-    synchronized void queueEvent(EventObject event, Vector vector) {
+    synchronized void queueEvent(EventObject event,
+                                 Vector<? extends NamingListener> vector) {
         if (eventQueue == null)
             eventQueue = new EventQueue();
 
@@ -340,7 +334,9 @@
          * of this event will not take effect until after the event is
          * delivered.
          */
-        Vector v = (Vector)vector.clone();
+        @SuppressWarnings("unchecked") // clone()
+        Vector<NamingListener> v =
+                (Vector<NamingListener>)vector.clone();
         eventQueue.enqueue(event, v);
     }
 
--- a/src/share/classes/com/sun/jndi/ldap/LdapAttribute.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapAttribute.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,6 @@
 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.*;
@@ -50,11 +48,12 @@
     // 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;
     }
 
@@ -112,7 +111,7 @@
     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");
@@ -144,9 +143,10 @@
      * 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;
@@ -156,16 +156,14 @@
         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);
                 }
--- a/src/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java	Mon Jan 30 08:02:44 2017 +0000
@@ -32,11 +32,13 @@
 import java.util.Vector;
 import javax.naming.*;
 import javax.naming.directory.*;
+import javax.naming.ldap.Control;
 import javax.naming.spi.*;
 
 import com.sun.jndi.toolkit.ctx.Continuation;
 
-final class LdapBindingEnumeration extends LdapNamingEnumeration {
+final class LdapBindingEnumeration
+        extends AbstractLdapNamingEnumeration<Binding> {
 
     private final AccessControlContext acc = AccessController.getContext();
 
@@ -46,8 +48,9 @@
         super(homeCtx, answer, remain, cont);
     }
 
-    protected NameClassPair
-      createItem(String dn, final Attributes attrs, Vector respCtls)
+    @Override
+    protected Binding
+      createItem(String dn, final Attributes attrs, Vector<Control> respCtls)
         throws NamingException {
 
         Object obj = null;
@@ -100,9 +103,10 @@
         return binding;
     }
 
-    protected LdapNamingEnumeration
-    getReferredResults(LdapReferralContext refCtx) throws NamingException{
+    @Override
+    protected LdapBindingEnumeration getReferredResults(
+            LdapReferralContext refCtx) throws NamingException{
         // repeat the original operation at the new context
-        return (LdapNamingEnumeration) refCtx.listBindings(listArg);
+        return (LdapBindingEnumeration)refCtx.listBindings(listArg);
     }
 }
--- a/src/share/classes/com/sun/jndi/ldap/LdapClient.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapClient.java	Mon Jan 30 08:02:44 2017 +0000
@@ -25,7 +25,6 @@
 
 package com.sun.jndi.ldap;
 
-import java.net.*;
 import java.io.*;
 import java.util.Vector;
 import java.util.Hashtable;
@@ -81,7 +80,8 @@
     static final boolean caseIgnore = true;
 
     // Default list of binary attributes
-    private static final Hashtable defaultBinaryAttrs = new Hashtable(23,0.75f);
+    private static final Hashtable<String, Boolean> defaultBinaryAttrs =
+            new Hashtable<>(23,0.75f);
     static {
         defaultBinaryAttrs.put("userpassword", Boolean.TRUE);      //2.5.4.35
         defaultBinaryAttrs.put("javaserializeddata", Boolean.TRUE);
@@ -146,7 +146,7 @@
 
     synchronized LdapResult
     authenticate(boolean initial, String name, Object pw, int version,
-        String authMechanism, Control[] ctls,  Hashtable env)
+        String authMechanism, Control[] ctls,  Hashtable<?,?> env)
         throws NamingException {
 
         int readTimeout = conn.readTimeout;
@@ -524,8 +524,8 @@
     LdapResult search(String dn, int scope, int deref, int sizeLimit,
                       int timeLimit, boolean attrsOnly, String attrs[],
                       String filter, int batchSize, Control[] reqCtls,
-                      Hashtable binaryAttrs, boolean waitFirstReply,
-                      int replyQueueCapacity)
+                      Hashtable<String, Boolean> binaryAttrs,
+                      boolean waitFirstReply, int replyQueueCapacity)
         throws IOException, NamingException {
 
         ensureOpen();
@@ -594,7 +594,7 @@
      * Retrieve the next batch of entries and/or referrals.
      */
     LdapResult getSearchReply(int batchSize, LdapResult res,
-        Hashtable binaryAttrs) throws IOException, NamingException {
+        Hashtable<String, Boolean> binaryAttrs) throws IOException, NamingException {
 
         ensureOpen();
 
@@ -608,7 +608,7 @@
     }
 
     private LdapResult getSearchReply(LdapRequest req,
-        int batchSize, LdapResult res, Hashtable binaryAttrs)
+        int batchSize, LdapResult res, Hashtable<String, Boolean> binaryAttrs)
         throws IOException, NamingException {
 
         if (batchSize == 0)
@@ -618,7 +618,7 @@
             res.entries.setSize(0); // clear the (previous) set of entries
         } else {
             res.entries =
-                new Vector(batchSize == Integer.MAX_VALUE ? 32 : batchSize);
+                new Vector<>(batchSize == Integer.MAX_VALUE ? 32 : batchSize);
         }
 
         if (res.referrals != null) {
@@ -668,7 +668,7 @@
             } else if ((seq == LDAP_REP_SEARCH_REF) && isLdapv3) {
 
                 // handle LDAPv3 search reference
-                Vector URLs = new Vector(4);
+                Vector<String> URLs = new Vector<>(4);
 
                 // %%% Although not strictly correct, some LDAP servers
                 //     encode the SEQUENCE OF tag in the SearchResultRef
@@ -684,7 +684,7 @@
                 }
 
                 if (res.referrals == null) {
-                    res.referrals = new Vector(4);
+                    res.referrals = new Vector<>(4);
                 }
                 res.referrals.addElement(URLs);
                 res.resControls = isLdapv3 ? parseControls(replyBer) : null;
@@ -708,7 +708,8 @@
         return res;
     }
 
-    private Attribute parseAttribute(BerDecoder ber, Hashtable binaryAttrs)
+    private Attribute parseAttribute(BerDecoder ber,
+                                     Hashtable<String, Boolean> binaryAttrs)
         throws IOException {
 
         int len[] = new int[1];
@@ -750,7 +751,8 @@
         return len[0];
     }
 
-    private boolean isBinaryValued(String attrid, Hashtable binaryAttrs) {
+    private boolean isBinaryValued(String attrid,
+                                   Hashtable<String, Boolean> binaryAttrs) {
         String id = attrid.toLowerCase();
 
         return ((id.indexOf(";binary") != -1) ||
@@ -771,7 +773,7 @@
             (replyBer.bytesLeft() > 0) &&
             (replyBer.peekByte() == LDAP_REP_REFERRAL)) {
 
-            Vector URLs = new Vector(4);
+            Vector<String> URLs = new Vector<>(4);
             int[] seqlen = new int[1];
 
             replyBer.parseSeq(seqlen);
@@ -783,18 +785,18 @@
             }
 
             if (res.referrals == null) {
-                res.referrals = new Vector(4);
+                res.referrals = new Vector<>(4);
             }
             res.referrals.addElement(URLs);
         }
     }
 
     // package entry point; used by Connection
-    static Vector parseControls(BerDecoder replyBer) throws IOException {
+    static Vector<Control> parseControls(BerDecoder replyBer) throws IOException {
 
         // handle LDAPv3 controls (if present)
         if ((replyBer.bytesLeft() > 0) && (replyBer.peekByte() == LDAP_CONTROLS)) {
-            Vector ctls = new Vector(4);
+            Vector<Control> ctls = new Vector<>(4);
             String controlOID;
             boolean criticality = false; // default
             byte[] controlValue = null;  // optional
@@ -965,7 +967,7 @@
         ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
             ber.encodeString(attr.getID(), isLdapv3);
             ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR | 1);
-                NamingEnumeration enum_ = attr.getAll();
+                NamingEnumeration<?> enum_ = attr.getAll();
                 Object val;
                 while (enum_.hasMore()) {
                     val = enum_.next();
@@ -1015,9 +1017,10 @@
                 ber.beginSeq(LDAP_REQ_ADD);
                     ber.encodeString(entry.DN, isLdapv3);
                     ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
-                        NamingEnumeration enum_ = entry.attributes.getAll();
+                        NamingEnumeration<? extends Attribute> enum_ =
+                                entry.attributes.getAll();
                         while (enum_.hasMore()) {
-                            attr = (Attribute)enum_.next();
+                            attr = enum_.next();
 
                             // zero values is not permitted
                             if (hasNoValue(attr)) {
@@ -1482,7 +1485,7 @@
     // removeUnsolicited() is invoked to remove an LdapCtx from this client.
     //
     ////////////////////////////////////////////////////////////////////////////
-    private Vector unsolicited = new Vector(3);
+    private Vector<LdapCtx> unsolicited = new Vector<>(3);
     void addUnsolicited(LdapCtx ctx) {
         if (debug > 0) {
             System.err.println("LdapClient.addUnsolicited" + ctx);
@@ -1508,70 +1511,70 @@
         if (debug > 0) {
             System.err.println("LdapClient.processUnsolicited");
         }
-      synchronized (unsolicited) {
-        try {
-            // Parse the response
-            LdapResult res = new LdapResult();
+        synchronized (unsolicited) {
+            try {
+                // Parse the response
+                LdapResult res = new LdapResult();
 
-            ber.parseSeq(null); // init seq
-            ber.parseInt();             // msg id; should be 0; ignored
-            if (ber.parseByte() != LDAP_REP_EXTENSION) {
-                throw new IOException(
-                    "Unsolicited Notification must be an Extended Response");
+                ber.parseSeq(null); // init seq
+                ber.parseInt();             // msg id; should be 0; ignored
+                if (ber.parseByte() != LDAP_REP_EXTENSION) {
+                    throw new IOException(
+                        "Unsolicited Notification must be an Extended Response");
+                }
+                ber.parseLength();
+                parseExtResponse(ber, res);
+
+                if (DISCONNECT_OID.equals(res.extensionId)) {
+                    // force closing of connection
+                    forceClose(pooled);
+                }
+
+                if (unsolicited.size() > 0) {
+                    // Create an UnsolicitedNotification using the parsed data
+                    // Need a 'ctx' object because we want to use the context's
+                    // list of provider control factories.
+                    UnsolicitedNotification notice = new UnsolicitedResponseImpl(
+                        res.extensionId,
+                        res.extensionValue,
+                        res.referrals,
+                        res.status,
+                        res.errorMessage,
+                        res.matchedDN,
+                        (res.resControls != null) ?
+                        unsolicited.elementAt(0).convertControls(res.resControls) :
+                        null);
+
+                    // Fire UnsolicitedNotification events to listeners
+                    notifyUnsolicited(notice);
+
+                    // If "disconnect" notification,
+                    // notify unsolicited listeners via NamingException
+                    if (DISCONNECT_OID.equals(res.extensionId)) {
+                        notifyUnsolicited(
+                            new CommunicationException("Connection closed"));
+                    }
+                }
+            } catch (IOException e) {
+                if (unsolicited.size() == 0)
+                    return;  // no one registered; ignore
+
+                NamingException ne = new CommunicationException(
+                    "Problem parsing unsolicited notification");
+                ne.setRootCause(e);
+
+                notifyUnsolicited(ne);
+
+            } catch (NamingException e) {
+                notifyUnsolicited(e);
             }
-            ber.parseLength();
-            parseExtResponse(ber, res);
-
-            if (DISCONNECT_OID.equals(res.extensionId)) {
-                // force closing of connection
-                forceClose(pooled);
-            }
-
-            if (unsolicited.size() > 0) {
-                // Create an UnsolicitedNotification using the parsed data
-                // Need a 'ctx' object because we want to use the context's
-                // list of provider control factories.
-                UnsolicitedNotification notice = new UnsolicitedResponseImpl(
-                    res.extensionId,
-                    res.extensionValue,
-                    res.referrals,
-                    res.status,
-                    res.errorMessage,
-                    res.matchedDN,
-                    (res.resControls != null) ?
-            ((LdapCtx)unsolicited.elementAt(0)).convertControls(res.resControls) :
-                    null);
-
-                // Fire UnsolicitedNotification events to listeners
-                notifyUnsolicited(notice);
-
-                // If "disconnect" notification,
-                // notify unsolicited listeners via NamingException
-                if (DISCONNECT_OID.equals(res.extensionId)) {
-                    notifyUnsolicited(
-                        new CommunicationException("Connection closed"));
-                }
-            }
-        } catch (IOException e) {
-            if (unsolicited.size() == 0)
-                return;  // no one registered; ignore
-
-            NamingException ne = new CommunicationException(
-                "Problem parsing unsolicited notification");
-            ne.setRootCause(e);
-
-            notifyUnsolicited(ne);
-
-        } catch (NamingException e) {
-            notifyUnsolicited(e);
         }
-      }
     }
 
 
     private void notifyUnsolicited(Object e) {
         for (int i = 0; i < unsolicited.size(); i++) {
-            ((LdapCtx)unsolicited.elementAt(i)).fireUnsolicited(e);
+            unsolicited.elementAt(i).fireUnsolicited(e);
         }
         if (e instanceof NamingException) {
             unsolicited.setSize(0);  // no more listeners after exception
@@ -1592,7 +1595,7 @@
     static LdapClient getInstance(boolean usePool, String hostname, int port,
         String factory, int connectTimeout, int readTimeout, OutputStream trace,
         int version, String authMechanism, Control[] ctls, String protocol,
-        String user, Object passwd, Hashtable env) throws NamingException {
+        String user, Object passwd, Hashtable<?,?> env) throws NamingException {
 
         if (usePool) {
             if (LdapPoolManager.isPoolingAllowed(factory, trace,
--- a/src/share/classes/com/sun/jndi/ldap/LdapCtx.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapCtx.java	Mon Jan 30 08:02:44 2017 +0000
@@ -223,7 +223,7 @@
     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.
@@ -232,7 +232,7 @@
 
     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
 
 
@@ -244,14 +244,14 @@
     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
@@ -272,13 +272,15 @@
 
     // -------------- 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))) {
@@ -310,7 +312,7 @@
             this.useDefaultPortNumber = true;
         }
 
-        schemaTrees = new Hashtable(11, 0.75f);
+        schemaTrees = new Hashtable<>(11, 0.75f);
         initEnv();
         try {
             connect(false);
@@ -557,9 +559,7 @@
                 if (answer.resControls != null) {
                     respCtls = appendVector(respCtls, answer.resControls);
                 }
-            } catch (NamingException ae) {
-                addEx = ae;
-            } catch (IOException ae) {
+            } catch (NamingException | IOException ae) {
                 addEx = ae;
             }
 
@@ -918,19 +918,17 @@
             }
 
             // 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) {
@@ -961,12 +959,12 @@
     }
 
 
-    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;
              }
@@ -993,7 +991,7 @@
      * 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 {
@@ -1038,10 +1036,10 @@
                 // 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
                 }
@@ -1097,7 +1095,7 @@
         }
     }
 
-    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];
@@ -1170,7 +1168,7 @@
         }
     }
 
-    protected NamingEnumeration c_listBindings(Name name, Continuation cont)
+    protected NamingEnumeration<Binding> c_listBindings(Name name, Continuation cont)
             throws NamingException {
 
         SearchControls cons = new SearchControls();
@@ -1198,7 +1196,7 @@
 
             // process the referrals sequentially
             while (true) {
-
+                @SuppressWarnings("unchecked")
                 LdapReferralContext refCtx =
                     (LdapReferralContext)e.getReferralContext(envprops, bindCtls);
 
@@ -1220,16 +1218,14 @@
             LdapBindingEnumeration res =
                 new LdapBindingEnumeration(this, answer, name, cont);
 
-            res.setNamingException(
-                    (LimitExceededException)cont.fillInException(e));
+            res.setNamingException(cont.fillInException(e));
             return res;
 
         } catch (PartialResultException e) {
             LdapBindingEnumeration res =
                 new LdapBindingEnumeration(this, answer, name, cont);
 
-            res.setNamingException(
-                    (PartialResultException)cont.fillInException(e));
+            res.setNamingException(cont.fillInException(e));
             return res;
 
         } catch (NamingException e) {
@@ -1337,9 +1333,9 @@
             }
 
             // get attributes from result
-            LdapEntry entry = (LdapEntry) answer.entries.elementAt(0);
-
-            Vector entryCtls = entry.respCtls; // retrieve entry controls
+            LdapEntry entry = answer.entries.elementAt(0);
+
+            Vector<Control> entryCtls = entry.respCtls; // retrieve entry controls
             if (entryCtls != null) {
                 appendVector(respCtls, entryCtls); // concatenate controls
             }
@@ -1398,10 +1394,10 @@
             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);
@@ -1565,7 +1561,7 @@
             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?
@@ -1591,7 +1587,7 @@
     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);}
@@ -1621,7 +1617,7 @@
                 false /*deref link */ );
 
         Name sse = (new CompositeName()).add(subschemasubentry);
-        NamingEnumeration results =
+        NamingEnumeration<SearchResult> results =
             searchAux(sse, "(objectClass=subschema)", constraints,
             false, true, new Continuation());
 
@@ -1629,7 +1625,7 @@
             throw new OperationNotSupportedException(
                 "Cannot get read subschemasubentry: " + subschemasubentry);
         }
-        SearchResult result = (SearchResult)results.next();
+        SearchResult result = results.next();
         results.close();
 
         Object obj = result.getObject();
@@ -1674,7 +1670,7 @@
             false /* returning obj */,
             false /* deref link */);
 
-        NamingEnumeration results;
+        NamingEnumeration<SearchResult> results;
         try {
             results = searchAux(name, "objectclass=*", constraints, relative,
                 true, new Continuation());
@@ -1695,7 +1691,7 @@
                 "Requesting schema of nonexistent entry: " + name);
         }
 
-        SearchResult result = (SearchResult) results.next();
+        SearchResult result = results.next();
         results.close();
 
         Attribute schemaEntryAttr =
@@ -1720,7 +1716,7 @@
     // 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);
         }
@@ -1740,14 +1736,14 @@
     }
 
    // --------------------- 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)
@@ -1764,7 +1760,7 @@
         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)
@@ -1773,7 +1769,7 @@
                  waitForReply, cont);
     }
 
-    protected NamingEnumeration c_search(Name name,
+    protected NamingEnumeration<SearchResult> c_search(Name name,
                                          String filterExpr,
                                          Object[] filterArgs,
                                          SearchControls cons,
@@ -1790,7 +1786,7 @@
     }
 
         // Used by NamingNotifier
-    NamingEnumeration searchAux(Name name,
+    NamingEnumeration<SearchResult> searchAux(Name name,
         String filter,
         SearchControls cons,
         boolean relative,
@@ -1849,7 +1845,8 @@
                 processReturnCode(answer, name);
             }
             return new LdapSearchEnumeration(this, answer,
-                fullyQualifiedName(name), args, cont);
+                                             fullyQualifiedName(name),
+                                             args, cont);
 
         } catch (LdapReferralException e) {
             if (handleReferrals == LdapClient.LDAP_REF_THROW)
@@ -1858,8 +1855,9 @@
             // process the referrals sequentially
             while (true) {
 
-                LdapReferralContext refCtx =
-                    (LdapReferralContext)e.getReferralContext(envprops, bindCtls);
+                @SuppressWarnings("unchecked")
+                LdapReferralContext refCtx = (LdapReferralContext)
+                        e.getReferralContext(envprops, bindCtls);
 
                 // repeat the original operation at the new context
                 try {
@@ -2143,16 +2141,18 @@
     /**
      * Override with noncloning version.
      */
-    protected Hashtable p_getEnvironment() {
+    protected Hashtable<String, Object> p_getEnvironment() {
         return envprops;
     }
 
-    public Hashtable getEnvironment() throws NamingException {
+    @SuppressWarnings("unchecked") // clone()
+    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") // clone()
     public Object removeFromEnvironment(String propName)
         throws NamingException {
 
@@ -2160,58 +2160,74 @@
         if (envprops == null || envprops.get(propName) == null) {
             return null;
         }
-
-        if (propName.equals(REF_SEPARATOR)) {
-            addrEncodingSeparator = DEFAULT_REF_SEPARATOR;
-        } else if (propName.equals(TYPES_ONLY)) {
-            typesOnly = DEFAULT_TYPES_ONLY;
-        } else if (propName.equals(DELETE_RDN)) {
-            deleteRDN = DEFAULT_DELETE_RDN;
-        } else if (propName.equals(DEREF_ALIASES)) {
-            derefAliases = DEFAULT_DEREF_ALIASES;
-        } else if (propName.equals(Context.BATCHSIZE)) {
-            batchSize = DEFAULT_BATCH_SIZE;
-        } else if (propName.equals(REFERRAL_LIMIT)) {
-            referralHopLimit = DEFAULT_REFERRAL_LIMIT;
-        } else if (propName.equals(Context.REFERRAL)) {
-            setReferralMode(null, true);
-        } else if (propName.equals(BINARY_ATTRIBUTES)) {
-            setBinaryAttributes(null);
-        } else if (propName.equals(CONNECT_TIMEOUT)) {
-            connectTimeout = -1;
-        } else if (propName.equals(READ_TIMEOUT)) {
-            readTimeout = -1;
-        } else if (propName.equals(WAIT_FOR_REPLY)) {
-            waitForReply = true;
-        } else if (propName.equals(REPLY_QUEUE_SIZE)) {
-            replyQueueSize = -1;
-
-// The following properties affect the connection
-
-        } else if (propName.equals(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;
+        switch (propName) {
+            case REF_SEPARATOR:
+                addrEncodingSeparator = DEFAULT_REF_SEPARATOR;
+                break;
+            case TYPES_ONLY:
+                typesOnly = DEFAULT_TYPES_ONLY;
+                break;
+            case DELETE_RDN:
+                deleteRDN = DEFAULT_DELETE_RDN;
+                break;
+            case DEREF_ALIASES:
+                derefAliases = DEFAULT_DEREF_ALIASES;
+                break;
+            case Context.BATCHSIZE:
+                batchSize = DEFAULT_BATCH_SIZE;
+                break;
+            case REFERRAL_LIMIT:
+                referralHopLimit = DEFAULT_REFERRAL_LIMIT;
+                break;
+            case Context.REFERRAL:
+                setReferralMode(null, true);
+                break;
+            case BINARY_ATTRIBUTES:
+                setBinaryAttributes(null);
+                break;
+            case CONNECT_TIMEOUT:
+                connectTimeout = -1;
+                break;
+            case READ_TIMEOUT:
+                readTimeout = -1;
+                break;
+            case WAIT_FOR_REPLY:
+                waitForReply = true;
+                break;
+            case REPLY_QUEUE_SIZE:
+                replyQueueSize = -1;
+                break;
+
+            // The following properties affect the connection
+
+            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)) {
-            closeConnection(SOFT_CLOSE);
-        } else if(propName.equals(Context.SECURITY_AUTHENTICATION) ||
-            propName.equals(Context.SECURITY_PRINCIPAL) ||
-            propName.equals(Context.SECURITY_CREDENTIALS)) {
-            sharable = false;
+                break;
+            case VERSION:
+            case SOCKET_FACTORY:
+                closeConnection(SOFT_CLOSE);
+                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") // clone()
     public Object addToEnvironment(String propName, Object propVal)
         throws NamingException {
 
@@ -2219,57 +2235,72 @@
             if (propVal == null) {
                 return removeFromEnvironment(propName);
             }
-
-            if (propName.equals(REF_SEPARATOR)) {
-                setRefSeparator((String)propVal);
-            } else if (propName.equals(TYPES_ONLY)) {
-                setTypesOnly((String)propVal);
-            } else if (propName.equals(DELETE_RDN)) {
-                setDeleteRDN((String)propVal);
-            } else if (propName.equals(DEREF_ALIASES)) {
-                setDerefAliases((String)propVal);
-            } else if (propName.equals(Context.BATCHSIZE)) {
-                setBatchSize((String)propVal);
-            } else if (propName.equals(REFERRAL_LIMIT)) {
-                setReferralLimit((String)propVal);
-            } else if (propName.equals(Context.REFERRAL)) {
-                setReferralMode((String)propVal, true);
-            } else if (propName.equals(BINARY_ATTRIBUTES)) {
-                setBinaryAttributes((String)propVal);
-            } else if (propName.equals(CONNECT_TIMEOUT)) {
-                setConnectTimeout((String)propVal);
-            } else if (propName.equals(READ_TIMEOUT)) {
-                setReadTimeout((String)propVal);
-            } else if (propName.equals(WAIT_FOR_REPLY)) {
-                setWaitForReply((String)propVal);
-            } else if (propName.equals(REPLY_QUEUE_SIZE)) {
-                setReplyQueueSize((String)propVal);
-
-// The following properties affect the connection
-
-            } else if (propName.equals(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;
+            switch (propName) {
+                case REF_SEPARATOR:
+                    setRefSeparator((String)propVal);
+                    break;
+                case TYPES_ONLY:
+                    setTypesOnly((String)propVal);
+                    break;
+                case DELETE_RDN:
+                    setDeleteRDN((String)propVal);
+                    break;
+                case DEREF_ALIASES:
+                    setDerefAliases((String)propVal);
+                    break;
+                case Context.BATCHSIZE:
+                    setBatchSize((String)propVal);
+                    break;
+                case REFERRAL_LIMIT:
+                    setReferralLimit((String)propVal);
+                    break;
+                case Context.REFERRAL:
+                    setReferralMode((String)propVal, true);
+                    break;
+                case BINARY_ATTRIBUTES:
+                    setBinaryAttributes((String)propVal);
+                    break;
+                case CONNECT_TIMEOUT:
+                    setConnectTimeout((String)propVal);
+                    break;
+                case READ_TIMEOUT:
+                    setReadTimeout((String)propVal);
+                    break;
+                case WAIT_FOR_REPLY:
+                    setWaitForReply((String)propVal);
+                    break;
+                case REPLY_QUEUE_SIZE:
+                    setReplyQueueSize((String)propVal);
+                    break;
+
+            // The following properties affect the connection
+
+                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)) {
-                closeConnection(SOFT_CLOSE);
-            } else if (propName.equals(Context.SECURITY_AUTHENTICATION) ||
-                propName.equals(Context.SECURITY_PRINCIPAL) ||
-                propName.equals(Context.SECURITY_CREDENTIALS)) {
-                sharable = false;
+                    break;
+                case VERSION:
+                case SOCKET_FACTORY:
+                    closeConnection(SOFT_CLOSE);
+                    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);
     }
 
@@ -2380,15 +2411,19 @@
     private void setReferralMode(String ref, boolean update) {
         // First determine the referral mode
         if (ref != null) {
-            if (ref.equals("follow")) {
-                handleReferrals = LdapClient.LDAP_REF_FOLLOW;
-            } else if (ref.equals("throw")) {
-                handleReferrals = LdapClient.LDAP_REF_THROW;
-            } else if (ref.equals("ignore")) {
-                handleReferrals = LdapClient.LDAP_REF_IGNORE;
-            } else {
-                throw new IllegalArgumentException(
-                    "Illegal value for " + Context.REFERRAL + " property.");
+            switch (ref) {
+                case "follow":
+                    handleReferrals = LdapClient.LDAP_REF_FOLLOW;
+                    break;
+                case "throw":
+                    handleReferrals = LdapClient.LDAP_REF_THROW;
+                    break;
+                case "ignore":
+                    handleReferrals = LdapClient.LDAP_REF_IGNORE;
+                    break;
+                default:
+                    throw new IllegalArgumentException(
+                        "Illegal value for " + Context.REFERRAL + " property.");
             }
         } else {
             handleReferrals = DEFAULT_REFERRAL_MODE;
@@ -2411,17 +2446,22 @@
      */
     private void setDerefAliases(String deref) {
         if (deref != null) {
-            if (deref.equals("never")) {
-                derefAliases = 0; // never de-reference aliases
-            } else if (deref.equals("searching")) {
-                derefAliases = 1; // de-reference aliases during searching
-            } else if (deref.equals("finding")) {
-                derefAliases = 2; // de-reference during name resolution
-            } else if (deref.equals("always")) {
-                derefAliases = 3; // always de-reference aliases
-            } else {
-                throw new IllegalArgumentException("Illegal value for " +
-                    DEREF_ALIASES + " property.");
+            switch (deref) {
+                case "never":
+                    derefAliases = 0; // never de-reference aliases
+                    break;
+                case "searching":
+                    derefAliases = 1; // de-reference aliases during searching
+                    break;
+                case "finding":
+                    derefAliases = 2; // de-reference during name resolution
+                    break;
+                case "always":
+                    derefAliases = 3; // always de-reference aliases
+                    break;
+                default:
+                    throw new IllegalArgumentException("Illegal value for " +
+                        DEREF_ALIASES + " property.");
             }
         } else {
             derefAliases = DEFAULT_DEREF_ALIASES;
@@ -2514,8 +2554,10 @@
      *     <ldapurls>   ::= <separator> <ldapurl> | <ldapurls>
      *     <separator>  ::= ASCII linefeed character (0x0a)
      *     <ldapurl>    ::= LDAP URL format (RFC 1959)
+     *
+     * Returns a Vector of single-String Vectors.
      */
-    private static Vector extractURLs(String refString) {
+    private static Vector<Vector<String>> extractURLs(String refString) {
 
         int separator = 0;
         int urlCount = 0;
@@ -2526,17 +2568,21 @@
             urlCount++;
         }
 
-        Vector referrals = new Vector(urlCount);
+        Vector<Vector<String>> referrals = new Vector<>(urlCount);
         int iURL;
         int i = 0;
 
         separator = refString.indexOf('\n');
         iURL = separator + 1;
         while ((separator = refString.indexOf('\n', iURL)) >= 0) {
-            referrals.addElement(refString.substring(iURL, separator));
+            Vector<String> referral = new Vector<>(1);
+            referral.addElement(refString.substring(iURL, separator));
+            referrals.addElement(referral);
             iURL = separator + 1;
         }
-        referrals.addElement(refString.substring(iURL));
+        Vector<String> referral = new Vector<>(1);
+        referral.addElement(refString.substring(iURL));
+        referrals.addElement(referral);
 
         return referrals;
     }
@@ -2549,7 +2595,7 @@
         if (attrIds == null) {
             binaryAttrs = null;
         } else {
-            binaryAttrs = new Hashtable(11, 0.75f);
+            binaryAttrs = new Hashtable<>(11, 0.75f);
             StringTokenizer tokens =
                 new StringTokenizer(attrIds.toLowerCase(), " ");
 
@@ -2601,11 +2647,12 @@
 */
     }
 
+    @SuppressWarnings("unchecked") // clone()
     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);
@@ -2631,7 +2678,7 @@
                 }
 
                 // 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) {
@@ -2644,7 +2691,7 @@
                     }
                 }
                 // reset the cache before a new connection is established
-                schemaTrees = new Hashtable(11, 0.75f);
+                schemaTrees = new Hashtable<>(11, 0.75f);
                 connect(startTLS);
             }
 
@@ -2846,7 +2893,7 @@
     }
 
     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);
@@ -2880,7 +2927,7 @@
                     r = new LdapReferralException(resolvedName, resolvedObj,
                         remainName, msg, envprops, fullDN, handleReferrals,
                         reqCtls);
-                    r.setReferralInfo((Vector)res.referrals.elementAt(i), true);
+                    r.setReferralInfo(res.referrals.elementAt(i), true);
 
                     if (hopCount > 1) {
                         r.setHopCount(hopCount);
@@ -2927,7 +2974,7 @@
             r = new LdapReferralException(resolvedName, resolvedObj, remainName,
                 msg, envprops, fullDN, handleReferrals, reqCtls);
             // only one set of URLs is present
-            r.setReferralInfo((Vector)res.referrals.elementAt(0), false);
+            r.setReferralInfo(res.referrals.elementAt(0), false);
 
             if (hopCount > 1) {
                 r.setHopCount(hopCount);
@@ -2995,10 +3042,10 @@
              *     If 1 referral and 0 entries is received then
              *     assume name resolution has not yet completed.
              */
-            if (((res.entries == null) || (res.entries.size() == 0)) &&
+            if (((res.entries == null) || (res.entries.isEmpty())) &&
                 (res.referrals.size() == 1)) {
 
-                r.setReferralInfo((Vector)res.referrals, false);
+                r.setReferralInfo(res.referrals, false);
 
                 // check the hop limit
                 if (hopCount > referralHopLimit) {
@@ -3284,9 +3331,9 @@
 
     /**
      * 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) {
@@ -3298,12 +3345,12 @@
         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;
@@ -3448,7 +3495,7 @@
             if (nm.size() > 1) {
                 throw new InvalidNameException(
                     "Target cannot span multiple namespaces: " + nm);
-            } else if (nm.size() == 0) {
+            } else if (nm.isEmpty()) {
                 return "";
             } else {
                 return nm.get(0);
--- a/src/share/classes/com/sun/jndi/ldap/LdapCtxFactory.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapCtxFactory.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,6 @@
 import java.util.Hashtable;
 import java.util.Vector;
 import java.util.Enumeration;
-import java.net.MalformedURLException;
 
 import javax.naming.*;
 import javax.naming.directory.*;
@@ -119,9 +118,9 @@
         int size = 0;   // number of URLs
         String[] urls = new String[ref.size()];
 
-        Enumeration addrs = ref.getAll();
+        Enumeration<RefAddr> addrs = ref.getAll();
         while (addrs.hasMoreElements()) {
-            RefAddr addr = (RefAddr)addrs.nextElement();
+            RefAddr addr = addrs.nextElement();
 
             if ((addr instanceof StringRefAddr) &&
                 addr.getType().equals(ADDRESS_TYPE)) {
@@ -145,7 +144,7 @@
 
     // ------------ Utilities used by other classes ----------------
 
-    public static DirContext getLdapCtxInstance(Object urlInfo, Hashtable env)
+    public static DirContext getLdapCtxInstance(Object urlInfo, Hashtable<?,?> env)
             throws NamingException {
 
         if (urlInfo instanceof String) {
@@ -158,7 +157,7 @@
         }
     }
 
-    private static DirContext getUsingURL(String url, Hashtable env)
+    private static DirContext getUsingURL(String url, Hashtable<?,?> env)
             throws NamingException {
         DirContext ctx = null;
         LdapURL ldapUrl = new LdapURL(url);
@@ -202,7 +201,7 @@
      * If all URLs fail, throw one of the exceptions arbitrarily.
      * Not pretty, but potentially more informative than returning null.
      */
-    private static DirContext getUsingURLs(String[] urls, Hashtable env)
+    private static DirContext getUsingURLs(String[] urls, Hashtable<?,?> env)
             throws NamingException {
         NamingException ne = null;
         DirContext ctx = null;
@@ -221,8 +220,8 @@
     /**
      * Used by Obj and obj/RemoteToAttrs too so must be public
      */
-    public static Attribute createTypeNameAttr(Class cl) {
-        Vector v = new Vector(10);
+    public static Attribute createTypeNameAttr(Class<?> cl) {
+        Vector<String> v = new Vector<>(10);
         String[] types = getTypeNames(cl, v);
         if (types.length > 0) {
             BasicAttribute tAttr =
@@ -235,7 +234,7 @@
         return null;
     }
 
-    private static String[] getTypeNames(Class currentClass, Vector v) {
+    private static String[] getTypeNames(Class<?> currentClass, Vector<String> v) {
 
         getClassesAux(currentClass, v);
         Class[] members = currentClass.getInterfaces();
@@ -244,13 +243,14 @@
         }
         String[] ret = new String[v.size()];
         int i = 0;
-        for (java.util.Enumeration e = v.elements(); e.hasMoreElements();) {
-            ret[i++] = (String)e.nextElement();
+
+        for (String name : v) {
+            ret[i++] = name;
         }
         return ret;
     }
 
-    private static void getClassesAux(Class currentClass, Vector v) {
+    private static void getClassesAux(Class<?> currentClass, Vector<String> v) {
         if (!v.contains(currentClass.getName())) {
             v.addElement(currentClass.getName());
         }
--- a/src/share/classes/com/sun/jndi/ldap/LdapEntry.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapEntry.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,7 @@
 
 import java.util.Vector;
 import javax.naming.directory.Attributes;
-import javax.naming.directory.Attribute;
+import javax.naming.ldap.Control;
 
 /**
   * A holder for an LDAP entry read from an LDAP server.
@@ -38,14 +38,14 @@
 final class LdapEntry {
     String DN;
     Attributes attributes;
-    Vector respCtls = null;
+    Vector<Control> respCtls = null;
 
     LdapEntry(String DN, Attributes attrs) {
         this.DN = DN;
         this.attributes = attrs;
     }
 
-    LdapEntry(String DN, Attributes attrs, Vector respCtls) {
+    LdapEntry(String DN, Attributes attrs, Vector<Control> respCtls) {
         this.DN = DN;
         this.attributes = attrs;
         this.respCtls = respCtls;
--- a/src/share/classes/com/sun/jndi/ldap/LdapName.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapName.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -78,7 +78,7 @@
 public final class LdapName implements Name {
 
     private transient String unparsed;  // if non-null, the DN in unparsed form
-    private transient Vector rdns;      // parsed name components
+    private transient Vector<Rdn> rdns;      // parsed name components
     private transient boolean valuesCaseSensitive = false;
 
     /**
@@ -97,9 +97,10 @@
      * Constructs an LDAP name given its parsed components and, optionally
      * (if "name" is not null), the unparsed DN.
      */
-    private LdapName(String name, Vector rdns) {
+    @SuppressWarnings("unchecked") // clone()
+    private LdapName(String name, Vector<Rdn> rdns) {
         unparsed = name;
-        this.rdns = (Vector)rdns.clone();
+        this.rdns = (Vector<Rdn>)rdns.clone();
     }
 
     /*
@@ -107,9 +108,9 @@
      * of "rdns" in the range [beg,end)) and, optionally
      * (if "name" is not null), the unparsed DN.
      */
-    private LdapName(String name, Vector rdns, int beg, int end) {
+    private LdapName(String name, Vector<Rdn> rdns, int beg, int end) {
         unparsed = name;
-        this.rdns = new Vector();
+        this.rdns = new Vector<>();
         for (int i = beg; i < end; i++) {
             this.rdns.addElement(rdns.elementAt(i));
         }
@@ -130,7 +131,7 @@
             if (i < rdns.size() - 1) {
                 buf.append(',');
             }
-            Rdn rdn = (Rdn)rdns.elementAt(i);
+            Rdn rdn = rdns.elementAt(i);
             buf.append(rdn);
         }
 
@@ -155,8 +156,8 @@
         int minSize = Math.min(rdns.size(), that.rdns.size());
         for (int i = 0 ; i < minSize; i++) {
             // Compare a single pair of RDNs.
-            Rdn rdn1 = (Rdn)rdns.elementAt(i);
-            Rdn rdn2 = (Rdn)that.rdns.elementAt(i);
+            Rdn rdn1 = rdns.elementAt(i);
+            Rdn rdn2 = that.rdns.elementAt(i);
 
             int diff = rdn1.compareTo(rdn2);
             if (diff != 0) {
@@ -172,7 +173,7 @@
 
         // For each RDN...
         for (int i = 0; i < rdns.size(); i++) {
-            Rdn rdn = (Rdn)rdns.elementAt(i);
+            Rdn rdn = rdns.elementAt(i);
             hash += rdn.hashCode();
         }
         return hash;
@@ -186,14 +187,14 @@
         return rdns.isEmpty();
     }
 
-    public Enumeration getAll() {
-        final Enumeration enum_ = rdns.elements();
+    public Enumeration<String> getAll() {
+        final Enumeration<Rdn> enum_ = rdns.elements();
 
-        return new Enumeration () {
+        return new Enumeration<String>() {
             public boolean hasMoreElements() {
                 return enum_.hasMoreElements();
             }
-            public Object nextElement() {
+            public String nextElement() {
                 return enum_.nextElement().toString();
             }
         };
@@ -254,7 +255,7 @@
             Rdn rdn;
             if (n instanceof LdapName) {
                 LdapName ln = (LdapName)n;
-                rdn = (Rdn)ln.rdns.elementAt(i - beg);
+                rdn = ln.rdns.elementAt(i - beg);
             } else {
                 String rdnString = n.get(i - beg);
                 try {
@@ -286,9 +287,9 @@
                 rdns.insertElementAt(s.rdns.elementAt(i), pos++);
             }
         } else {
-            Enumeration comps = suffix.getAll();
+            Enumeration<String> comps = suffix.getAll();
             while (comps.hasMoreElements()) {
-                DnParser p = new DnParser((String)comps.nextElement(),
+                DnParser p = new DnParser(comps.nextElement(),
                     valuesCaseSensitive);
                 rdns.insertElementAt(p.getRdn(), pos++);
             }
@@ -406,9 +407,9 @@
         /*
          * Parses the DN, returning a Vector of its RDNs.
          */
-        Vector getDn() throws InvalidNameException {
+        Vector<Rdn> getDn() throws InvalidNameException {
             cur = 0;
-            Vector rdns = new Vector(len / 3 + 10);  // leave room for growth
+            Vector<Rdn> rdns = new Vector<>(len / 3 + 10);  // leave room for growth
 
             if (len == 0) {
                 return rdns;
@@ -595,7 +596,7 @@
          * A vector of the TypeAndValue elements of this Rdn.
          * It is sorted to facilitate set operations.
          */
-        private final Vector tvs = new Vector();
+        private final Vector<TypeAndValue> tvs = new Vector<>();
 
         void add(TypeAndValue tv) {
 
@@ -636,7 +637,7 @@
             int minSize = Math.min(tvs.size(), that.tvs.size());
             for (int i = 0; i < minSize; i++) {
                 // Compare a single pair of type/value pairs.
-                TypeAndValue tv = (TypeAndValue)tvs.elementAt(i);
+                TypeAndValue tv = tvs.elementAt(i);
                 int diff = tv.compareTo(that.tvs.elementAt(i));
                 if (diff != 0) {
                     return diff;
@@ -662,7 +663,7 @@
             Attribute attr;
 
             for (int i = 0; i < tvs.size(); i++) {
-                tv = (TypeAndValue) tvs.elementAt(i);
+                tv = tvs.elementAt(i);
                 if ((attr = attrs.get(tv.getType())) == null) {
                     attrs.put(tv.getType(), tv.getUnescapedValue());
                 } else {
--- a/src/share/classes/com/sun/jndi/ldap/LdapNamingEnumeration.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapNamingEnumeration.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,267 +27,25 @@
 
 import javax.naming.*;
 import javax.naming.directory.*;
-import javax.naming.spi.*;
 
 import com.sun.jndi.toolkit.ctx.Continuation;
-import java.util.NoSuchElementException;
 import java.util.Vector;
-import javax.naming.ldap.LdapName;
+import javax.naming.ldap.Control;
 
-/**
-  * Basic enumeration for NameClassPair, Binding, and SearchResults.
-  */
 
-class LdapNamingEnumeration implements NamingEnumeration, ReferralEnumeration {
-    protected Name listArg;
-
-    private boolean cleaned = false;
-    private LdapResult res;
-    private LdapClient enumClnt;
-    private Continuation cont;  // used to fill in exceptions
-    private Vector entries = null;
-    private int limit = 0;
-    private int posn = 0;
-    protected LdapCtx homeCtx;
-    private LdapReferralException refEx = null;
-    private NamingException errEx = null;
+final class LdapNamingEnumeration
+        extends AbstractLdapNamingEnumeration<NameClassPair> {
 
     private static final String defaultClassName = DirContext.class.getName();
 
-    /*
-     * Record the next set of entries and/or referrals.
-     */
     LdapNamingEnumeration(LdapCtx homeCtx, LdapResult answer, Name listArg,
-        Continuation cont) throws NamingException {
-
-            // These checks are to accommodate referrals and limit exceptions
-            // which will generate an enumeration and defer the exception
-            // to be thrown at the end of the enumeration.
-            // All other exceptions are thrown immediately.
-            // Exceptions shouldn't be thrown here anyhow because
-            // process_return_code() is called before the constructor
-            // is called, so these are just safety checks.
-
-            if ((answer.status != LdapClient.LDAP_SUCCESS) &&
-                (answer.status != LdapClient.LDAP_SIZE_LIMIT_EXCEEDED) &&
-                (answer.status != LdapClient.LDAP_TIME_LIMIT_EXCEEDED) &&
-                (answer.status != LdapClient.LDAP_ADMIN_LIMIT_EXCEEDED) &&
-                (answer.status != LdapClient.LDAP_REFERRAL) &&
-                (answer.status != LdapClient.LDAP_PARTIAL_RESULTS)) {
-
-                // %%% need to deal with referral
-                NamingException e = new NamingException(
-                                    LdapClient.getErrorMessage(
-                                    answer.status, answer.errorMessage));
-
-                throw cont.fillInException(e);
-            }
-
-            // otherwise continue
-
-            res = answer;
-            entries = answer.entries;
-            limit = (entries == null) ? 0 : entries.size(); // handle empty set
-            this.listArg = listArg;
-            this.cont = cont;
-
-            if (answer.refEx != null) {
-                refEx = answer.refEx;
-            }
-
-            // Ensures that context won't get closed from underneath us
-            this.homeCtx = homeCtx;
-            homeCtx.incEnumCount();
-            enumClnt = homeCtx.clnt; // remember
+                                 Continuation cont) throws NamingException {
+        super(homeCtx, answer, listArg, cont);
     }
 
-    public Object nextElement() {
-        try {
-            return next();
-        } catch (NamingException e) {
-            // can't throw exception
-            cleanup();
-            return null;
-        }
-    }
-
-    public boolean hasMoreElements() {
-        try {
-            return hasMore();
-        } catch (NamingException e) {
-            // can't throw exception
-            cleanup();
-            return false;
-        }
-    }
-
-    /*
-     * Retrieve the next set of entries and/or referrals.
-     */
-    private void getNextBatch() throws NamingException {
-
-        res = homeCtx.getSearchReply(enumClnt, res);
-        if (res == null) {
-            limit = posn = 0;
-            return;
-        }
-
-        entries = res.entries;
-        limit = (entries == null) ? 0 : entries.size(); // handle empty set
-        posn = 0; // reset
-
-        // mimimize the number of calls to processReturnCode()
-        // (expensive when batchSize is small and there are many results)
-        if ((res.status != LdapClient.LDAP_SUCCESS) ||
-            ((res.status == LdapClient.LDAP_SUCCESS) &&
-                (res.referrals != null))) {
-
-            try {
-                // convert referrals into a chain of LdapReferralException
-                homeCtx.processReturnCode(res, listArg);
-
-            } catch (LimitExceededException e) {
-                setNamingException(e);
-
-            } catch (PartialResultException e) {
-                setNamingException(e);
-            }
-        }
-
-        // merge any newly received referrals with any current referrals
-        if (res.refEx != null) {
-            if (refEx == null) {
-                refEx = res.refEx;
-            } else {
-                refEx = refEx.appendUnprocessedReferrals(res.refEx);
-            }
-            res.refEx = null; // reset
-        }
-
-        if (res.resControls != null) {
-            homeCtx.respCtls = res.resControls;
-        }
-    }
-
-    private boolean more = true;  // assume we have something to start with
-    private boolean hasMoreCalled = false;
-
-    /*
-     * Test if unprocessed entries or referrals exist.
-     */
-    public boolean hasMore() throws NamingException {
-
-        if (hasMoreCalled) {
-            return more;
-        }
-
-        hasMoreCalled = true;
-
-        if (!more) {
-            return false;
-        } else {
-            return (more = hasMoreImpl());
-        }
-    }
-
-    /*
-     * Retrieve the next entry.
-     */
-    public Object next() throws NamingException {
-
-        if (!hasMoreCalled) {
-            hasMore();
-        }
-        hasMoreCalled = false;
-        return nextImpl();
-    }
-
-    /*
-     * Test if unprocessed entries or referrals exist.
-     */
-    private boolean hasMoreImpl() throws NamingException {
-        // when page size is supported, this
-        // might generate an exception while attempting
-        // to fetch the next batch to determine
-        // whether there are any more elements
-
-        // test if the current set of entries has been processed
-        if (posn == limit) {
-            getNextBatch();
-        }
-
-        // test if any unprocessed entries exist
-        if (posn < limit) {
-            return true;
-        } else {
-
-            try {
-                // try to process another referral
-                return hasMoreReferrals();
-
-            } catch (LdapReferralException e) {
-                cleanup();
-                throw e;
-
-            } catch (LimitExceededException e) {
-                cleanup();
-                throw e;
-
-            } catch (PartialResultException e) {
-                cleanup();
-                throw e;
-
-            } catch (NamingException e) {
-                cleanup();
-                PartialResultException pre = new PartialResultException();
-                pre.setRootCause(e);
-                throw pre;
-            }
-        }
-    }
-
-    /*
-     * Retrieve the next entry.
-     */
-    private Object nextImpl() throws NamingException {
-        try {
-            return nextAux();
-        } catch (NamingException e) {
-            cleanup();
-            throw cont.fillInException(e);
-        }
-    }
-
-    private Object nextAux() throws NamingException {
-        if (posn == limit) {
-            getNextBatch();  // updates posn and limit
-        }
-
-        if (posn >= limit) {
-            cleanup();
-            throw new NoSuchElementException("invalid enumeration handle");
-        }
-
-        LdapEntry result = (LdapEntry)entries.elementAt(posn++);
-
-        // gets and outputs DN from the entry
-        return createItem(result.DN, result.attributes, result.respCtls);
-    }
-
-    protected String getAtom(String dn) {
-        String atom;
-        // need to strip off all but lowest component of dn
-        // so that is relative to current context (currentDN)
-        try {
-            Name parsed = new LdapName(dn);
-            return parsed.get(parsed.size() - 1);
-        } catch (NamingException e) {
-            return dn;
-        }
-    }
-
+    @Override
     protected NameClassPair createItem(String dn, Attributes attrs,
-        Vector respCtls) throws NamingException {
+            Vector<Control> respCtls) throws NamingException {
 
         Attribute attr;
         String className = null;
@@ -313,128 +71,10 @@
         return ncp;
     }
 
-    /*
-     * Append the supplied (chain of) referrals onto the
-     * end of the current (chain of) referrals.
-     */
-    public void appendUnprocessedReferrals(LdapReferralException ex) {
-
-        if (refEx != null) {
-            refEx = refEx.appendUnprocessedReferrals(ex);
-        } else {
-            refEx = ex.appendUnprocessedReferrals(refEx);
-        }
-    }
-
-    void setNamingException(NamingException e) {
-        errEx = e;
-    }
-
-    protected LdapNamingEnumeration
-    getReferredResults(LdapReferralContext refCtx) throws NamingException {
+    @Override
+    protected LdapNamingEnumeration getReferredResults(
+            LdapReferralContext refCtx) throws NamingException {
         // repeat the original operation at the new context
         return (LdapNamingEnumeration)refCtx.list(listArg);
     }
-
-    /*
-     * Iterate through the URLs of a referral. If successful then perform
-     * a search operation and merge the received results with the current
-     * results.
-     */
-    protected boolean hasMoreReferrals() throws NamingException {
-
-        if ((refEx != null) &&
-            (refEx.hasMoreReferrals() ||
-             refEx.hasMoreReferralExceptions())) {
-
-            if (homeCtx.handleReferrals == LdapClient.LDAP_REF_THROW) {
-                throw (NamingException)(refEx.fillInStackTrace());
-            }
-
-            // process the referrals sequentially
-            while (true) {
-
-                LdapReferralContext refCtx =
-                    (LdapReferralContext)refEx.getReferralContext(
-                    homeCtx.envprops, homeCtx.reqCtls);
-
-                try {
-
-                    update(getReferredResults(refCtx));
-                    break;
-
-                } catch (LdapReferralException re) {
-
-                    // record a previous exception
-                    if (errEx == null) {
-                        errEx = re.getNamingException();
-                    }
-                    refEx = re;
-                    continue;
-
-                } finally {
-                    // Make sure we close referral context
-                    refCtx.close();
-                }
-            }
-            return hasMoreImpl();
-
-        } else {
-            cleanup();
-
-            if (errEx != null) {
-                throw errEx;
-            }
-            return (false);
-        }
-    }
-
-    /*
-     * Merge the entries and/or referrals from the supplied enumeration
-     * with those of the current enumeration.
-     */
-    protected void update(LdapNamingEnumeration ne) {
-        // Cleanup previous context first
-        homeCtx.decEnumCount();
-
-        // New enum will have already incremented enum count and recorded clnt
-        homeCtx = ne.homeCtx;
-        enumClnt = ne.enumClnt;
-
-        // Do this to prevent referral enumeration (ne) from decrementing
-        // enum count because we'll be doing that here from this
-        // enumeration.
-        ne.homeCtx = null;
-
-        // Record rest of information from new enum
-        posn = ne.posn;
-        limit = ne.limit;
-        res = ne.res;
-        entries = ne.entries;
-        refEx = ne.refEx;
-        listArg = ne.listArg;
-    }
-
-    protected void finalize() {
-        cleanup();
-    }
-
-    protected void cleanup() {
-        if (cleaned) return; // been there; done that
-
-        if(enumClnt != null) {
-            enumClnt.clearSearchReply(res, homeCtx.reqCtls);
-        }
-
-        enumClnt = null;
-        cleaned = true;
-        if (homeCtx != null) {
-            homeCtx.decEnumCount();
-            homeCtx = null;
-        }
-    }
-
-    public void close() {
-        cleanup();
-    }
 }
--- a/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -214,7 +214,7 @@
      *
      */
     static boolean isPoolingAllowed(String socketFactory, OutputStream trace,
-        String authMech, String protocol, Hashtable env)
+        String authMech, String protocol, Hashtable<?,?> env)
                 throws NamingException {
 
         if (trace != null && !debug
@@ -235,7 +235,7 @@
         if ((socketFactory != null) &&
              !socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) {
             try {
-                Class socketFactoryClass = Obj.helper.loadClass(socketFactory);
+                Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory);
                 Class[] interfaces = socketFactoryClass.getInterfaces();
                 for (int i = 0; i < interfaces.length; i++) {
                     if (interfaces[i].getCanonicalName().equals(COMPARATOR)) {
@@ -294,7 +294,7 @@
     static LdapClient getLdapClient(String host, int port, String socketFactory,
         int connTimeout, int readTimeout, OutputStream trace, int version,
         String authMech, Control[] ctls, String protocol, String user,
-        Object passwd, Hashtable env) throws NamingException {
+        Object passwd, Hashtable<?,?> env) throws NamingException {
 
         // Create base identity for LdapClient
         ClientId id = null;
@@ -385,9 +385,9 @@
 
     private static final String getProperty(final String propName,
         final String defVal) {
-        return (String) AccessController.doPrivileged(
-            new PrivilegedAction() {
-            public Object run() {
+        return AccessController.doPrivileged(
+            new PrivilegedAction<String>() {
+            public String run() {
                 try {
                     return System.getProperty(propName, defVal);
                 } catch (SecurityException e) {
@@ -399,9 +399,9 @@
 
     private static final int getInteger(final String propName,
         final int defVal) {
-        Integer val = (Integer) AccessController.doPrivileged(
-            new PrivilegedAction() {
-            public Object run() {
+        Integer val = AccessController.doPrivileged(
+            new PrivilegedAction<Integer>() {
+            public Integer run() {
                 try {
                     return Integer.getInteger(propName, defVal);
                 } catch (SecurityException e) {
@@ -414,9 +414,9 @@
 
     private static final long getLong(final String propName,
         final long defVal) {
-        Long val = (Long) AccessController.doPrivileged(
-            new PrivilegedAction() {
-            public Object run() {
+        Long val = AccessController.doPrivileged(
+            new PrivilegedAction<Long>() {
+            public Long run() {
                 try {
                     return Long.getLong(propName, defVal);
                 } catch (SecurityException e) {
--- a/src/share/classes/com/sun/jndi/ldap/LdapReferralContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapReferralContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -52,7 +52,9 @@
     private int hopCount = 1;
     private NamingException previousEx = null;
 
-    LdapReferralContext(LdapReferralException ex, Hashtable env,
+    @SuppressWarnings("unchecked") // clone()
+    LdapReferralContext(LdapReferralException ex,
+        Hashtable<?,?> env,
         Control[] connCtls,
         Control[] reqCtls,
         String nextName,
@@ -69,20 +71,21 @@
 
         // Make copies of environment and connect controls for our own use.
         if (env != null) {
-            env = (Hashtable) env.clone();
+            env = (Hashtable<?,?>) env.clone();
             // Remove old connect controls from environment, unless we have new
             // ones that will override them anyway.
             if (connCtls == null) {
                 env.remove(LdapCtx.BIND_CONTROLS);
             }
         } else if (connCtls != null) {
-            env = new Hashtable(5);
+            env = new Hashtable<String, Control[]>(5);
         }
         if (connCtls != null) {
             Control[] copiedCtls = new Control[connCtls.length];
             System.arraycopy(connCtls, 0, copiedCtls, 0, connCtls.length);
             // Add copied controls to environment, replacing any old ones.
-            env.put(LdapCtx.BIND_CONTROLS, copiedCtls);
+            ((Hashtable<? super String, ? super Control[]>)env)
+                    .put(LdapCtx.BIND_CONTROLS, copiedCtls);
         }
 
         while (true) {
@@ -260,24 +263,26 @@
         refCtx.rename(overrideName(oldName), toName(refEx.getNewRdn()));
     }
 
-    public NamingEnumeration list(String name) throws NamingException {
+    public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
         return list(toName(name));
     }
 
-    public NamingEnumeration list(Name name) throws NamingException {
+    @SuppressWarnings("unchecked")
+    public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
         if (skipThisReferral) {
             throw (NamingException)
                 ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());
         }
         try {
-            NamingEnumeration ne = null;
+            NamingEnumeration<NameClassPair> ne = null;
 
             if (urlScope != null && urlScope.equals("base")) {
                 SearchControls cons = new SearchControls();
                 cons.setReturningObjFlag(true);
                 cons.setSearchScope(SearchControls.OBJECT_SCOPE);
 
-                ne = refCtx.search(overrideName(name), "(objectclass=*)", cons);
+                ne = (NamingEnumeration)
+                        refCtx.search(overrideName(name), "(objectclass=*)", cons);
 
             } else {
                 ne = refCtx.list(overrideName(name));
@@ -318,25 +323,29 @@
         }
     }
 
-    public NamingEnumeration listBindings(String name) throws NamingException {
+    public NamingEnumeration<Binding> listBindings(String name) throws
+            NamingException {
         return listBindings(toName(name));
     }
 
-    public NamingEnumeration listBindings(Name name) throws NamingException {
+    @SuppressWarnings("unchecked")
+    public NamingEnumeration<Binding> listBindings(Name name) throws
+            NamingException {
         if (skipThisReferral) {
             throw (NamingException)
                 ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());
         }
 
         try {
-            NamingEnumeration be = null;
+            NamingEnumeration<Binding> be = null;
 
             if (urlScope != null && urlScope.equals("base")) {
                 SearchControls cons = new SearchControls();
                 cons.setReturningObjFlag(true);
                 cons.setSearchScope(SearchControls.OBJECT_SCOPE);
 
-                be = refCtx.search(overrideName(name), "(objectclass=*)", cons);
+                be = (NamingEnumeration)refCtx.search(overrideName(name),
+                        "(objectclass=*)", cons);
 
             } else {
                 be = refCtx.listBindings(overrideName(name));
@@ -347,7 +356,7 @@
             // append (referrals from) the exception that generated this
             // context to the new search results, so that referral processing
             // can continue
-            ((ReferralEnumeration)be).appendUnprocessedReferrals(refEx);
+            ((ReferralEnumeration<Binding>)be).appendUnprocessedReferrals(refEx);
 
             return (be);
 
@@ -462,7 +471,7 @@
         return refCtx.removeFromEnvironment(propName);
     }
 
-    public Hashtable getEnvironment() throws NamingException {
+    public Hashtable<?,?> getEnvironment() throws NamingException {
         if (skipThisReferral) {
             throw (NamingException)
                 ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());
@@ -602,23 +611,23 @@
       return refCtx.getSchemaClassDefinition(overrideName(name));
     }
 
-    public NamingEnumeration search(String name,
-                                    Attributes matchingAttributes)
+    public NamingEnumeration<SearchResult> search(String name,
+                                                  Attributes matchingAttributes)
             throws NamingException {
         return search(toName(name), SearchFilter.format(matchingAttributes),
             new SearchControls());
     }
 
-    public NamingEnumeration search(Name name,
-                                    Attributes matchingAttributes)
+    public NamingEnumeration<SearchResult> search(Name name,
+                                                  Attributes matchingAttributes)
             throws NamingException {
         return search(name, SearchFilter.format(matchingAttributes),
             new SearchControls());
     }
 
-    public NamingEnumeration search(String name,
-                                    Attributes matchingAttributes,
-                                    String[] attributesToReturn)
+    public NamingEnumeration<SearchResult> search(String name,
+                                                  Attributes matchingAttributes,
+                                                  String[] attributesToReturn)
             throws NamingException {
         SearchControls cons = new SearchControls();
         cons.setReturningAttributes(attributesToReturn);
@@ -627,9 +636,9 @@
             cons);
     }
 
-    public NamingEnumeration search(Name name,
-                                    Attributes matchingAttributes,
-                                    String[] attributesToReturn)
+    public NamingEnumeration<SearchResult> search(Name name,
+                                                  Attributes matchingAttributes,
+                                                  String[] attributesToReturn)
             throws NamingException {
         SearchControls cons = new SearchControls();
         cons.setReturningAttributes(attributesToReturn);
@@ -637,15 +646,15 @@
         return search(name, SearchFilter.format(matchingAttributes), cons);
     }
 
-    public NamingEnumeration search(String name,
-                                    String filter,
-                                    SearchControls cons)
+    public NamingEnumeration<SearchResult> search(String name,
+                                                  String filter,
+                                                  SearchControls cons)
             throws NamingException {
         return search(toName(name), filter, cons);
     }
 
-    public NamingEnumeration search(Name name,
-                                    String filter,
+    public NamingEnumeration<SearchResult> search(Name name,
+                                                  String filter,
         SearchControls cons) throws NamingException {
 
         if (skipThisReferral) {
@@ -654,8 +663,10 @@
         }
 
         try {
-            NamingEnumeration se = refCtx.search(overrideName(name),
-                overrideFilter(filter), overrideAttributesAndScope(cons));
+            NamingEnumeration<SearchResult> se =
+                    refCtx.search(overrideName(name),
+                                  overrideFilter(filter),
+                                  overrideAttributesAndScope(cons));
 
             refEx.setNameResolved(true);
 
@@ -694,15 +705,15 @@
         }
     }
 
-    public NamingEnumeration search(String name,
-                                    String filterExpr,
-                                    Object[] filterArgs,
-                                    SearchControls cons)
+    public NamingEnumeration<SearchResult> search(String name,
+                                                  String filterExpr,
+                                                  Object[] filterArgs,
+                                                  SearchControls cons)
             throws NamingException {
         return search(toName(name), filterExpr, filterArgs, cons);
     }
 
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
         String filterExpr,
         Object[] filterArgs,
         SearchControls cons) throws NamingException {
@@ -713,7 +724,7 @@
         }
 
         try {
-            NamingEnumeration se;
+            NamingEnumeration<SearchResult> se;
 
             if (urlFilter != null) {
                 se = refCtx.search(overrideName(name), urlFilter,
--- a/src/share/classes/com/sun/jndi/ldap/LdapReferralException.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapReferralException.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
 package com.sun.jndi.ldap;
 
 import javax.naming.*;
-import javax.naming.spi.*;
 import javax.naming.ldap.Control;
 
 import java.util.Hashtable;
@@ -67,15 +66,16 @@
   */
 final public class LdapReferralException extends
     javax.naming.ldap.LdapReferralException {
+    private static final long serialVersionUID = 627059076356906399L;
 
         // ----------- fields initialized in constructor ---------------
     private int handleReferrals;
-    private Hashtable envprops;
+    private Hashtable<?,?> envprops;
     private String nextName;
     private Control[] reqCtls;
 
         // ----------- fields that have defaults -----------------------
-    private Vector referrals = null;    // alternatives,set by setReferralInfo()
+    private Vector<?> referrals = null; // alternatives,set by setReferralInfo()
     private int referralIndex = 0;      // index into referrals
     private int referralCount = 0;      // count of referrals
     private boolean foundEntry = false; // will stop when entry is found
@@ -98,7 +98,7 @@
         Object resolvedObj,
         Name remainingName,
         String explanation,
-        Hashtable envprops,
+        Hashtable<?,?> envprops,
         String nextName,
         int handleReferrals,
         Control[] reqCtls) {
@@ -210,7 +210,7 @@
     /**
      * Sets referral information.
      */
-    void setReferralInfo(Vector referrals, boolean continuationRef) {
+    void setReferralInfo(Vector<?> referrals, boolean continuationRef) {
         // %%% continuationRef is currently ignored
 
         if (debug)
--- a/src/share/classes/com/sun/jndi/ldap/LdapResult.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapResult.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 import java.util.Vector;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
+import javax.naming.ldap.Control;
 
 /**
   * %%% public for use by LdapSasl %%%
@@ -37,10 +38,11 @@
     public int status;                  // %%% public for use by LdapSasl
     String matchedDN;
     String errorMessage;
-    Vector referrals = null;
+    // Vector<String | Vector<String>>
+    Vector<Vector<String>> referrals = null;
     LdapReferralException refEx = null;
-    Vector entries = null;
-    Vector resControls = null;
+    Vector<LdapEntry> entries = null;
+    Vector<Control> resControls = null;
     public byte[] serverCreds = null;   // %%% public for use by LdapSasl
     String extensionId = null;          // string OID
     byte[] extensionValue = null;       // BER OCTET STRING
@@ -57,7 +59,7 @@
         switch (status) {
             case LdapClient.LDAP_COMPARE_TRUE:
                 status = LdapClient.LDAP_SUCCESS;
-                entries = new Vector(1,1);
+                entries = new Vector<>(1,1);
                 Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
                 LdapEntry entry = new LdapEntry( name, attrs );
                 entries.addElement(entry);
@@ -66,7 +68,7 @@
 
             case LdapClient.LDAP_COMPARE_FALSE:
                 status = LdapClient.LDAP_SUCCESS;
-                entries = new Vector(0);
+                entries = new Vector<>(0);
                 successful = true;
                 break;
 
--- a/src/share/classes/com/sun/jndi/ldap/LdapSchemaCtx.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapSchemaCtx.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -61,8 +61,9 @@
 
     private int objectType;
 
-    static DirContext createSchemaTree(Hashtable env, String subschemasubentry,
-        LdapCtx schemaEntry, Attributes schemaAttrs, boolean netscapeBug)
+    static DirContext createSchemaTree(Hashtable<String,Object> env,
+            String subschemasubentry, LdapCtx schemaEntry,
+            Attributes schemaAttrs, boolean netscapeBug)
         throws NamingException {
             try {
                 LdapSchemaParser parser = new LdapSchemaParser(netscapeBug);
@@ -71,7 +72,7 @@
                     schemaEntry, parser);
 
                 LdapSchemaCtx root = new LdapSchemaCtx(SCHEMA_ROOT, env, allinfo);
-                parser.LDAP2JNDISchema(schemaAttrs, root);
+                LdapSchemaParser.LDAP2JNDISchema(schemaAttrs, root);
                 return root;
             } catch (NamingException e) {
                 schemaEntry.close(); // cleanup
@@ -80,7 +81,8 @@
     }
 
     // Called by createNewCtx
-    private LdapSchemaCtx(int objectType, Hashtable environment, SchemaInfo info) {
+    private LdapSchemaCtx(int objectType, Hashtable<String,Object> environment,
+                          SchemaInfo info) {
         super(environment, LdapClient.caseIgnore);
 
         this.objectType = objectType;
@@ -223,9 +225,9 @@
     final private static Attributes deepClone(Attributes orig)
         throws NamingException {
         BasicAttributes copy = new BasicAttributes(true);
-        NamingEnumeration attrs = orig.getAll();
+        NamingEnumeration<? extends Attribute> attrs = orig.getAll();
         while (attrs.hasMore()) {
-            copy.put((Attribute)((Attribute)attrs.next()).clone());
+            copy.put((Attribute)attrs.next().clone());
         }
         return copy;
     }
@@ -409,13 +411,14 @@
             }
         }
 
-        private LdapCtx reopenEntry(Hashtable env) throws NamingException {
+        private LdapCtx reopenEntry(Hashtable<?,?> env) throws NamingException {
             // Use subschemasubentry name as DN
             return new LdapCtx(schemaEntryName, host, port,
                                 env, hasLdapsScheme);
         }
 
-        synchronized void modifyAttributes(Hashtable env, ModificationItem[] mods)
+        synchronized void modifyAttributes(Hashtable<?,?> env,
+                                           ModificationItem[] mods)
             throws NamingException {
             if (schemaEntry == null) {
                 schemaEntry = reopenEntry(env);
@@ -423,7 +426,7 @@
             schemaEntry.modifyAttributes("", mods);
         }
 
-        synchronized void modifyAttributes(Hashtable env, int mod,
+        synchronized void modifyAttributes(Hashtable<?,?> env, int mod,
             Attributes attrs) throws NamingException {
             if (schemaEntry == null) {
                 schemaEntry = reopenEntry(env);
--- a/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,6 @@
 
 import javax.naming.*;
 import javax.naming.directory.*;
-import java.util.Hashtable;
 import java.util.Vector;
 
 /**
@@ -141,9 +140,9 @@
                                                    LdapSchemaCtx schemaRoot)
         throws NamingException {
 
-        NamingEnumeration       objDescs;
-        Attributes      objDef;
-        LdapSchemaCtx   classDefTree;
+        NamingEnumeration<?> objDescs;
+        Attributes                objDef;
+        LdapSchemaCtx             classDefTree;
 
         // create the class def subtree
         Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
@@ -173,9 +172,9 @@
                                                 LdapSchemaCtx schemaRoot)
         throws NamingException {
 
-        NamingEnumeration       attrDescs;
-        Attributes      attrDef;
-        LdapSchemaCtx   attrDefTree;
+        NamingEnumeration<?> attrDescs;
+        Attributes           attrDef;
+        LdapSchemaCtx        attrDefTree;
 
         // create the AttributeDef subtree
         Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
@@ -206,9 +205,9 @@
                                                 LdapSchemaCtx schemaRoot)
         throws NamingException {
 
-        NamingEnumeration       syntaxDescs;
-        Attributes      syntaxDef;
-        LdapSchemaCtx   syntaxDefTree;
+        NamingEnumeration<?> syntaxDescs;
+        Attributes           syntaxDef;
+        LdapSchemaCtx        syntaxDefTree;
 
         // create the SyntaxDef subtree
         Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
@@ -239,9 +238,9 @@
                                                 LdapSchemaCtx schemaRoot)
         throws NamingException {
 
-        NamingEnumeration       matchRuleDescs;
-        Attributes      matchRuleDef;
-        LdapSchemaCtx   matchRuleDefTree;
+        NamingEnumeration<?> matchRuleDescs;
+        Attributes           matchRuleDef;
+        LdapSchemaCtx        matchRuleDefTree;
 
         // create the MatchRuleDef subtree
         Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
@@ -519,8 +518,8 @@
     final private static String[] readQDescrList(String string, int[] pos)
         throws NamingException {
 
-        int     begin, end;
-        Vector  values = new Vector(5);
+        int begin, end;
+        Vector<String> values = new Vector<>(5);
 
         if (debug) {
             System.err.println("ReadQDescrList: pos="+pos[0]);
@@ -553,7 +552,7 @@
 
         String[] answer = new String[values.size()];
         for (int i = 0; i < answer.length; i++) {
-            answer[i] = (String)values.elementAt(i);
+            answer[i] = values.elementAt(i);
         }
         return answer;
     }
@@ -614,7 +613,7 @@
 
         int     begin, cur, end;
         String  oidName = null;
-        Vector  values = new Vector(5);
+        Vector<String> values = new Vector<>(5);
 
         if (debug) {
             System.err.println("ReadOIDList: pos="+pos[0]);
@@ -663,7 +662,7 @@
 
         String[] answer = new String[values.size()];
         for (int i = 0; i < answer.length; i++) {
-            answer[i] = (String)values.elementAt(i);
+            answer[i] = values.elementAt(i);
         }
         return answer;
     }
@@ -843,10 +842,10 @@
             String attrId = null;
 
             // use enumeration because attribute ID is not known
-            for (NamingEnumeration ae = attrs.getAll();
+            for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
                 ae.hasMoreElements(); ) {
 
-                attr = (Attribute)ae.next();
+                attr = ae.next();
                 attrId = attr.getID();
 
                 // skip those already processed
@@ -973,10 +972,10 @@
             String attrId = null;
 
             // use enumeration because attribute ID is not known
-            for (NamingEnumeration ae = attrs.getAll();
+            for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
                 ae.hasMoreElements(); ) {
 
-                attr = (Attribute)ae.next();
+                attr = ae.next();
                 attrId = attr.getID();
 
                 // skip those already processed
@@ -1040,10 +1039,10 @@
             String attrId = null;
 
             // use enumeration because attribute ID is not known
-            for (NamingEnumeration ae = attrs.getAll();
+            for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
                 ae.hasMoreElements(); ) {
 
-                attr = (Attribute)ae.next();
+                attr = ae.next();
                 attrId = attr.getID();
 
                 // skip those already processed
@@ -1117,10 +1116,10 @@
             String attrId = null;
 
             // use enumeration because attribute ID is not known
-            for (NamingEnumeration ae = attrs.getAll();
+            for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
                 ae.hasMoreElements(); ) {
 
-                attr = (Attribute)ae.next();
+                attr = ae.next();
                 attrId = attr.getID();
 
                 // skip those already processed
@@ -1201,7 +1200,7 @@
         qdList.append(WHSP);
         qdList.append(OID_LIST_BEGIN);
 
-        NamingEnumeration values = attr.getAll();
+        NamingEnumeration<?> values = attr.getAll();
 
         while(values.hasMore()) {
             qdList.append(WHSP);
@@ -1238,7 +1237,7 @@
         oidList.append(WHSP);
         oidList.append(OID_LIST_BEGIN);
 
-        NamingEnumeration values = oidsAttr.getAll();
+        NamingEnumeration<?> values = oidsAttr.getAll();
         oidList.append(WHSP);
         oidList.append(values.next());
 
--- a/src/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java	Mon Jan 30 08:02:44 2017 +0000
@@ -38,7 +38,8 @@
 
 import com.sun.jndi.toolkit.ctx.Continuation;
 
-final class LdapSearchEnumeration extends LdapNamingEnumeration {
+final class LdapSearchEnumeration
+        extends AbstractLdapNamingEnumeration<SearchResult> {
 
     private Name startName;             // prefix of names of search results
     private LdapCtx.SearchArgs searchArgs = null;
@@ -58,9 +59,10 @@
         searchArgs = args;
     }
 
-    protected NameClassPair
-    createItem(String dn, final Attributes attrs, Vector respCtls)
-        throws NamingException {
+    @Override
+    protected SearchResult createItem(String dn, final Attributes attrs,
+                                      Vector<Control> respCtls)
+            throws NamingException {
 
         Object obj = null;
 
@@ -188,6 +190,7 @@
         return sr;
     }
 
+    @Override
     public void appendUnprocessedReferrals(LdapReferralException ex) {
 
         // a referral has been followed so do not create relative names
@@ -195,14 +198,16 @@
         super.appendUnprocessedReferrals(ex);
     }
 
-    protected LdapNamingEnumeration
-    getReferredResults(LdapReferralContext refCtx) throws NamingException {
+    @Override
+    protected LdapSearchEnumeration getReferredResults(
+            LdapReferralContext refCtx) throws NamingException {
         // repeat the original operation at the new context
-        return (LdapSearchEnumeration)
-            refCtx.search(searchArgs.name, searchArgs.filter, searchArgs.cons);
+        return (LdapSearchEnumeration)refCtx.search(
+                searchArgs.name, searchArgs.filter, searchArgs.cons);
     }
 
-    protected void update(LdapNamingEnumeration ne) {
+    @Override
+    protected void update(AbstractLdapNamingEnumeration<SearchResult> ne) {
         super.update(ne);
 
         // Update search-specific variables
--- a/src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,12 +50,12 @@
 final class NamingEventNotifier implements Runnable {
     private final static boolean debug = false;
 
-    private Vector namingListeners;
+    private Vector<NamingListener> namingListeners;
     private Thread worker;
     private LdapCtx context;
     private EventContext eventSrc;
     private EventSupport support;
-    private NamingEnumeration results;
+    private NamingEnumeration<SearchResult> results;
 
     // package private; used by EventSupport to remove it
     NotifierArgs info;
@@ -83,7 +83,7 @@
         context = (LdapCtx)ctx.newInstance(new Control[]{psearch});
         eventSrc = ctx;
 
-        namingListeners = new Vector();
+        namingListeners = new Vector<>();
         namingListeners.addElement(firstListener);
 
         worker = Obj.helper.createThread(this);
@@ -124,7 +124,8 @@
             // Change root of search results so that it will generate
             // names relative to the event context instead of that
             // named by nm
-            ((LdapSearchEnumeration)results).setStartName(context.currentParsedDN);
+            ((LdapSearchEnumeration)(NamingEnumeration)results)
+                    .setStartName(context.currentParsedDN);
 
             SearchResult si;
             Control[] respctls;
@@ -132,7 +133,7 @@
             long changeNum;
 
             while (results.hasMore()) {
-                si = (SearchResult)results.next();
+                si = results.next();
                 respctls = (si instanceof HasControls) ?
                     ((HasControls) si).getControls() : null;
 
--- a/src/share/classes/com/sun/jndi/ldap/NotifierArgs.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/NotifierArgs.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -133,7 +133,7 @@
     private int controlsCode() {
         if (controls == null) return 0;
 
-        int total = (int)controls.getTimeLimit() + (int)controls.getCountLimit() +
+        int total = controls.getTimeLimit() + (int)controls.getCountLimit() +
             (controls.getDerefLinkFlag() ? 1 : 0) +
             (controls.getReturningObjFlag() ? 1 : 0);
 
--- a/src/share/classes/com/sun/jndi/ldap/Obj.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/Obj.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -84,6 +84,7 @@
     /**
      * @deprecated
      */
+    @Deprecated
     private static final int REMOTE_LOC = 7;
 
     // LDAP object classes to support Java objects
@@ -206,13 +207,13 @@
         } else {
             StringTokenizer parser =
                 new StringTokenizer((String)codebaseAttr.get());
-            Vector vec = new Vector(10);
+            Vector<String> vec = new Vector<>(10);
             while (parser.hasMoreTokens()) {
                 vec.addElement(parser.nextToken());
             }
             String[] answer = new String[vec.size()];
             for (int i = 0; i < answer.length; i++) {
-                answer[i] = (String)vec.elementAt(i);
+                answer[i] = vec.elementAt(i);
             }
             return answer;
         }
@@ -410,10 +411,10 @@
              * Temporary Vector for decoded RefAddr addresses - used to ensure
              * unordered addresses are correctly re-ordered.
              */
-            Vector refAddrList = new Vector();
+            Vector<RefAddr> refAddrList = new Vector<>();
             refAddrList.setSize(attr.size());
 
-            for (NamingEnumeration vals = attr.getAll(); vals.hasMore(); ) {
+            for (NamingEnumeration<?> vals = attr.getAll(); vals.hasMore(); ) {
 
                 val = (String)vals.next();
 
@@ -488,7 +489,7 @@
 
             // Copy to real reference
             for (int i = 0; i < refAddrList.size(); i++) {
-                ref.add((RefAddr)refAddrList.elementAt(i));
+                ref.add(refAddrList.elementAt(i));
             }
         }
 
@@ -502,9 +503,9 @@
 
         try {
             ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-            ObjectOutputStream serial = new ObjectOutputStream(bytes);
-            serial.writeObject(obj);
-            serial.close();
+            try (ObjectOutputStream serial = new ObjectOutputStream(bytes)) {
+                serial.writeObject(obj);
+            }
 
             return (bytes.toByteArray());
 
@@ -524,18 +525,14 @@
         try {
             // Create ObjectInputStream for deserialization
             ByteArrayInputStream bytes = new ByteArrayInputStream(obj);
-            ObjectInputStream deserial = (cl == null ?
-                new ObjectInputStream(bytes) :
-                new LoaderInputStream(bytes, cl));
-
-            try {
+            try (ObjectInputStream deserial = cl == null ?
+                    new ObjectInputStream(bytes) :
+                    new LoaderInputStream(bytes, cl)) {
                 return deserial.readObject();
             } catch (ClassNotFoundException e) {
                 NamingException ne = new NamingException();
                 ne.setRootCause(e);
                 throw ne;
-            } finally {
-                deserial.close();
             }
         } catch (IOException e) {
             NamingException ne = new NamingException();
@@ -549,7 +546,7 @@
       */
     static Attributes determineBindAttrs(
         char separator, Object obj, Attributes attrs, boolean cloned,
-        Name name, Context ctx, Hashtable env)
+        Name name, Context ctx, Hashtable<?,?> env)
         throws NamingException {
 
         // Call state factories to convert object and attrs
@@ -582,10 +579,10 @@
 
         } else {
             // Get existing objectclass attribute
-            objectClass = (Attribute)attrs.get("objectClass");
+            objectClass = attrs.get("objectClass");
             if (objectClass == null && !attrs.isCaseIgnored()) {
                 // %%% workaround
-                objectClass = (Attribute)attrs.get("objectclass");
+                objectClass = attrs.get("objectclass");
             }
 
             // No objectclasses supplied, use "top" to start
@@ -614,8 +611,8 @@
             classLoader = cl;
         }
 
-        protected Class resolveClass(ObjectStreamClass desc) throws IOException,
-            ClassNotFoundException {
+        protected Class<?> resolveClass(ObjectStreamClass desc) throws
+                IOException, ClassNotFoundException {
             try {
                 // %%% Should use Class.forName(desc.getName(), false, classLoader);
                 // except we can't because that is only available on JDK1.2
@@ -625,15 +622,15 @@
             }
         }
 
-         protected Class resolveProxyClass(String[] interfaces) throws
+         protected Class<?> resolveProxyClass(String[] interfaces) throws
                 IOException, ClassNotFoundException {
              ClassLoader nonPublicLoader = null;
              boolean hasNonPublicInterface = false;
 
              // define proxy in class loader of non-public interface(s), if any
-             Class[] classObjs = new Class[interfaces.length];
+             Class<?>[] classObjs = new Class<?>[interfaces.length];
              for (int i = 0; i < interfaces.length; i++) {
-                 Class cl = Class.forName(interfaces[i], false, classLoader);
+                 Class<?> cl = Class.forName(interfaces[i], false, classLoader);
                  if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
                      if (hasNonPublicInterface) {
                          if (nonPublicLoader != cl.getClassLoader()) {
--- a/src/share/classes/com/sun/jndi/ldap/ReferralEnumeration.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/ReferralEnumeration.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,6 @@
 
 import javax.naming.NamingEnumeration;
 
-interface ReferralEnumeration extends NamingEnumeration {
+interface ReferralEnumeration<T> extends NamingEnumeration<T> {
     void appendUnprocessedReferrals(LdapReferralException ex);
 }
--- a/src/share/classes/com/sun/jndi/ldap/ServiceLocator.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/ServiceLocator.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,9 +26,7 @@
 package com.sun.jndi.ldap;
 
 import java.util.Arrays;
-import java.util.Enumeration;
 import java.util.Hashtable;
-import java.util.NoSuchElementException;
 import java.util.Random;
 import java.util.StringTokenizer;
 import java.util.List;
@@ -39,8 +37,6 @@
 import javax.naming.ldap.LdapName;
 import javax.naming.ldap.Rdn;
 
-import com.sun.jndi.ldap.LdapURL;
-
 /**
  * This class discovers the location of LDAP services by querying DNS.
  * See http://www.ietf.org/internet-drafts/draft-ietf-ldapext-locate-07.txt
@@ -78,10 +74,10 @@
         // process RDNs left-to-right
         //List<Rdn> rdnList = ldapName.getRdns();
 
-        List rdnList = ldapName.getRdns();
+        List<Rdn> rdnList = ldapName.getRdns();
         for (int i = rdnList.size() - 1; i >= 0; i--) {
             //Rdn rdn = rdnList.get(i);
-            Rdn rdn = (Rdn) rdnList.get(i);
+            Rdn rdn = rdnList.get(i);
 
             // single-valued RDN with a DC attribute
             if ((rdn.size() == 1) &&
@@ -117,7 +113,7 @@
      * @return An ordered list of hostports for the LDAP service or null if
      *         the service has not been located.
      */
-    static String[] getLdapService(String domainName, Hashtable environment) {
+    static String[] getLdapService(String domainName, Hashtable<?,?> environment) {
 
         if (domainName == null || domainName.length() == 0) {
             return null;
@@ -252,7 +248,7 @@
  * See http://www.ietf.org/rfc/rfc2782.txt
  */
 
-static class SrvRecord implements Comparable {
+static class SrvRecord implements Comparable<SrvRecord> {
 
     int priority;
     int weight;
@@ -284,8 +280,7 @@
      * Sort records in ascending order of priority value. For records with
      * equal priority move those with weight 0 to the top of the list.
      */
-    public int compareTo(Object o) {
-        SrvRecord that = (SrvRecord) o;
+    public int compareTo(SrvRecord that) {
         if (priority > that.priority) {
             return 1; // this > that
         } else if (priority < that.priority) {
--- a/src/share/classes/com/sun/jndi/ldap/SimpleClientId.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/SimpleClientId.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -54,9 +54,9 @@
         } else if (passwd instanceof String) {
             this.passwd = passwd;
         } else if (passwd instanceof byte[]) {
-            this.passwd = (byte[]) ((byte[])passwd).clone();
+            this.passwd = ((byte[])passwd).clone();
         } else if (passwd instanceof char[]) {
-            this.passwd = (char[]) ((char[])passwd).clone();
+            this.passwd = ((char[])passwd).clone();
         } else {
             this.passwd = passwd;
         }
--- a/src/share/classes/com/sun/jndi/ldap/UnsolicitedResponseImpl.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/UnsolicitedResponseImpl.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,7 +41,7 @@
     private NamingException exception;
     private Control[] controls;
 
-    UnsolicitedResponseImpl(String oid, byte[] berVal, Vector ref,
+    UnsolicitedResponseImpl(String oid, byte[] berVal, Vector<Vector<String>> ref,
         int status, String msg, String matchedDN, Control[] controls) {
         this.oid = oid;
         this.extensionValue = berVal;
@@ -50,7 +50,8 @@
             int len = ref.size();
             referrals = new String[len];
             for (int i = 0; i < len; i++) {
-                referrals[i] = (String)ref.elementAt(i);
+                // ref is a list of single-String Vectors
+                referrals[i] = ref.elementAt(i).elementAt(0);
             }
         }
         exception = LdapCtx.mapErrorCode(status, msg);
--- a/src/share/classes/com/sun/jndi/ldap/VersionHelper.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/VersionHelper.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -72,7 +72,7 @@
         return urlArray;
     }
 
-    abstract Class loadClass(String className) throws ClassNotFoundException;
+    abstract Class<?> loadClass(String className) throws ClassNotFoundException;
 
     abstract Thread createThread(Runnable r);
 }
--- a/src/share/classes/com/sun/jndi/ldap/VersionHelper12.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/VersionHelper12.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -67,15 +67,15 @@
             }
     }
 
-    Class loadClass(String className) throws ClassNotFoundException {
+    Class<?> loadClass(String className) throws ClassNotFoundException {
         ClassLoader cl = getContextClassLoader();
         return Class.forName(className, true, cl);
     }
 
     private ClassLoader getContextClassLoader() {
-        return (ClassLoader) AccessController.doPrivileged(
-            new PrivilegedAction() {
-                public Object run() {
+        return AccessController.doPrivileged(
+            new PrivilegedAction<ClassLoader>() {
+                public ClassLoader run() {
                     return Thread.currentThread().getContextClassLoader();
                 }
             }
--- a/src/share/classes/com/sun/jndi/ldap/ext/StartTlsResponseImpl.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/ext/StartTlsResponseImpl.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,16 +27,8 @@
 
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
 import java.io.IOException;
 
-import java.net.Socket;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
 import java.security.Principal;
 import java.security.cert.X509Certificate;
 import java.security.cert.CertificateException;
@@ -45,11 +37,9 @@
 import javax.net.ssl.SSLSocket;
 import javax.net.ssl.SSLSocketFactory;
 import javax.net.ssl.SSLPeerUnverifiedException;
-import javax.net.ssl.SSLContext;
 import javax.net.ssl.HostnameVerifier;
 import sun.security.util.HostnameChecker;
 
-import javax.naming.*;
 import javax.naming.ldap.*;
 import com.sun.jndi.ldap.Connection;
 
@@ -415,7 +405,7 @@
             // Use ciphersuite to determine whether Kerberos is active.
             if (session.getCipherSuite().startsWith("TLS_KRB5")) {
                 Principal principal = getPeerPrincipal(session);
-                if (!checker.match(hostname, principal)) {
+                if (!HostnameChecker.match(hostname, principal)) {
                     throw new SSLPeerUnverifiedException(
                         "hostname of the kerberos principal:" + principal +
                         " does not match the hostname:" + hostname);
--- a/src/share/classes/com/sun/jndi/ldap/pool/Connections.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/pool/Connections.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -71,10 +71,10 @@
 
     final private int maxSize;
     final private int prefSize;
-    final private List conns;
+    final private List<ConnectionDesc> conns;
 
     private boolean closed = false;   // Closed for business
-    private Reference ref; // maintains reference to id to prevent premature GC
+    private Reference<Object> ref; // maintains reference to id to prevent premature GC
 
     /**
      * @param id the identity (connection request) of the connections in the list
@@ -99,11 +99,11 @@
         } else {
             this.prefSize = prefSize;
         }
-        conns = new ArrayList(maxSize > 0 ? maxSize : DEFAULT_SIZE);
+        conns = new ArrayList<>(maxSize > 0 ? maxSize : DEFAULT_SIZE);
 
         // Maintain soft ref to id so that this Connections' entry in
         // Pool doesn't get GC'ed prematurely
-        ref = new SoftReference(id);
+        ref = new SoftReference<>(id);
 
         d("init size=", initSize);
         d("max size=", maxSize);
@@ -186,7 +186,7 @@
             // exceeds prefSize, then first look for an idle connection
             ConnectionDesc entry;
             for (int i = 0; i < size; i++) {
-                entry = (ConnectionDesc) conns.get(i);
+                entry = conns.get(i);
                 if ((conn = entry.tryUse()) != null) {
                     d("get(): use ", conn);
                     td("Use ", conn);
@@ -239,7 +239,7 @@
                 td("Release ", conn);
 
                 // Get ConnectionDesc from list to get correct state info
-                entry = (ConnectionDesc) conns.get(loc);
+                entry = conns.get(loc);
                 // Return connection to list, ready for reuse
                 entry.release();
             }
@@ -291,10 +291,10 @@
      * @return true if no more connections in list
      */
     synchronized boolean expire(long threshold) {
-        Iterator iter = conns.iterator();
+        Iterator<ConnectionDesc> iter = conns.iterator();
         ConnectionDesc entry;
         while (iter.hasNext()) {
-            entry = (ConnectionDesc) iter.next();
+            entry = iter.next();
             if (entry.expire(threshold)) {
                 d("expire(): removing ", entry);
                 td("Expired ", entry);
@@ -333,7 +333,7 @@
 
             ConnectionDesc entry;
             for (int i = 0; i < len; i++) {
-                entry = (ConnectionDesc) conns.get(i);
+                entry = conns.get(i);
                 use += entry.getUseCount();
                 switch (entry.getState()) {
                 case ConnectionDesc.BUSY:
--- a/src/share/classes/com/sun/jndi/ldap/pool/ConnectionsWeakRef.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/pool/ConnectionsWeakRef.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,11 +55,12 @@
  * reference to Connections used for closing (which in turn terminates
  * the Connection thread) it by monitoring the ReferenceQueue.
  */
-class ConnectionsWeakRef extends WeakReference {
+class ConnectionsWeakRef extends WeakReference<ConnectionsRef> {
 
     private final Connections conns;
 
-    ConnectionsWeakRef (ConnectionsRef connsRef, ReferenceQueue queue) {
+    ConnectionsWeakRef (ConnectionsRef connsRef,
+                        ReferenceQueue<? super ConnectionsRef> queue) {
         super(connsRef, queue);
         this.conns = connsRef.getConnections();
     }
--- a/src/share/classes/com/sun/jndi/ldap/pool/Pool.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/pool/Pool.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.Set;
 import java.util.LinkedList;
 
 import java.io.PrintStream;
@@ -83,17 +82,18 @@
     /*
      * Used for connections cleanup
      */
-    private static final ReferenceQueue queue = new ReferenceQueue();
-    private static final Collection weakRefs =
-                Collections.synchronizedList(new LinkedList());
+    private static final ReferenceQueue<ConnectionsRef> queue =
+        new ReferenceQueue<>();
+    private static final Collection<Reference<ConnectionsRef>> weakRefs =
+        Collections.synchronizedList(new LinkedList<Reference<ConnectionsRef>>());
 
     final private int maxSize;    // max num of identical conn per pool
     final private int prefSize;   // preferred num of identical conn per pool
     final private int initSize;   // initial number of identical conn to create
-    final private Map map;
+    final private Map<Object, ConnectionsRef> map;
 
     public Pool(int initSize, int prefSize, int maxSize) {
-        map = new WeakHashMap();
+        map = new WeakHashMap<>();
         this.prefSize = prefSize;
         this.maxSize = maxSize;
         this.initSize = initSize;
@@ -135,7 +135,8 @@
                 map.put(id, connsRef);
 
                 // Create a weak reference to ConnectionsRef
-                Reference weakRef = new ConnectionsWeakRef(connsRef, queue);
+                Reference<ConnectionsRef> weakRef =
+                        new ConnectionsWeakRef(connsRef, queue);
 
                 // Keep the weak reference through the element of a linked list
                 weakRefs.add(weakRef);
@@ -148,7 +149,7 @@
     }
 
     private Connections getConnections(Object id) {
-        ConnectionsRef ref = (ConnectionsRef) map.get(id);
+        ConnectionsRef ref = map.get(id);
         return (ref != null) ? ref.getConnections() : null;
     }
 
@@ -163,11 +164,10 @@
      */
     public void expire(long threshold) {
         synchronized (map) {
-            Collection coll = map.values();
-            Iterator iter = coll.iterator();
+            Iterator<ConnectionsRef> iter = map.values().iterator();
             Connections conns;
             while (iter.hasNext()) {
-                conns = ((ConnectionsRef) (iter.next())).getConnections();
+                conns = iter.next().getConnections();
                 if (conns.expire(threshold)) {
                     d("expire(): removing ", conns);
                     iter.remove();
@@ -202,7 +202,6 @@
 
 
     public void showStats(PrintStream out) {
-        Map.Entry entry;
         Object id;
         Connections conns;
 
@@ -212,13 +211,9 @@
         out.println("initial pool size: " + initSize);
         out.println("current pool size: " + map.size());
 
-        Set entries = map.entrySet();
-        Iterator iter = entries.iterator();
-
-        while (iter.hasNext()) {
-            entry = (Map.Entry) iter.next();
+        for (Map.Entry<Object, ConnectionsRef> entry : map.entrySet()) {
             id = entry.getKey();
-            conns = ((ConnectionsRef) entry.getValue()).getConnections();
+            conns = entry.getValue().getConnections();
             out.println("   " + id + ":" + conns.getStats());
         }
 
--- a/src/share/classes/com/sun/jndi/ldap/pool/PoolCleaner.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/pool/PoolCleaner.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,7 +41,7 @@
     public PoolCleaner(long period, Pool[] pools) {
         super();
         this.period = period;
-        this.pools = (Pool[]) pools.clone();
+        this.pools = pools.clone();
         setDaemon(true);
     }
 
--- a/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -57,7 +57,7 @@
         if (cred instanceof String) {
             passwd = ((String)cred).toCharArray();
         } else if (cred instanceof char[]) {
-            passwd = (char[])((char[])cred).clone();
+            passwd = ((char[])cred).clone();
         } else if (cred != null) {
             // assume UTF-8 encoding
             String orig = new String((byte[])cred, "UTF8");
--- a/src/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -89,9 +89,10 @@
      * @param bindCtls The possibly null controls to accompany the bind
      * @return LdapResult containing status of the bind
      */
+    @SuppressWarnings("unchecked")
     public static LdapResult saslBind(LdapClient clnt, Connection conn,
         String server, String dn, Object pw,
-        String authMech, Hashtable env, Control[] bindCtls)
+        String authMech, Hashtable<?,?> env, Control[] bindCtls)
         throws IOException, NamingException {
 
         SaslClient saslClnt = null;
@@ -112,7 +113,7 @@
         try {
             // Create SASL client to use using SASL package
             saslClnt = Sasl.createSaslClient(
-                mechs, authzId, "ldap", server, env, cbh);
+                mechs, authzId, "ldap", server, (Hashtable<String, ?>)env, cbh);
 
             if (saslClnt == null) {
                 throw new AuthenticationNotSupportedException(authMech);
@@ -185,13 +186,13 @@
       */
     private static String[] getSaslMechanismNames(String str) {
         StringTokenizer parser = new StringTokenizer(str);
-        Vector mechs = new Vector(10);
+        Vector<String> mechs = new Vector<>(10);
         while (parser.hasMoreTokens()) {
             mechs.addElement(parser.nextToken());
         }
         String[] mechNames = new String[mechs.size()];
         for (int i = 0; i < mechs.size(); i++) {
-            mechNames[i] = (String)mechs.elementAt(i);
+            mechNames[i] = mechs.elementAt(i);
         }
         return mechNames;
     }
--- a/src/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,7 @@
 
 public class RegistryContext implements Context, Referenceable {
 
-    private Hashtable environment;
+    private Hashtable<String, Object> environment;
     private Registry registry;
     private String host;
     private int port;
@@ -87,10 +87,13 @@
      * Cloning of "env" is handled by caller; see comments within
      * RegistryContextFactory.getObjectInstance(), for example.
      */
-    public RegistryContext(String host, int port, Hashtable env)
+    @SuppressWarnings("unchecked")
+    public RegistryContext(String host, int port, Hashtable<?, ?> env)
             throws NamingException
     {
-        environment = ((env == null) ? new Hashtable(5) : env);
+        environment = (env == null)
+                      ? new Hashtable<String, Object>(5)
+                      : (Hashtable<String, Object>) env;
         if (environment.get(SECURITY_MGR) != null) {
             installSecurityMgr();
         }
@@ -113,8 +116,9 @@
      * won't close the other).
      */
     // %%% Alternatively, this could be done with a clone() method.
+    @SuppressWarnings("unchecked") // clone()
     RegistryContext(RegistryContext ctx) {
-        environment = (Hashtable)ctx.environment.clone();
+        environment = (Hashtable<String, Object>)ctx.environment.clone();
         registry = ctx.registry;
         host = ctx.host;
         port = ctx.port;
@@ -215,7 +219,8 @@
         rename(new CompositeName(name), new CompositeName(newName));
     }
 
-    public NamingEnumeration list(Name name)    throws NamingException {
+    public NamingEnumeration<NameClassPair> list(Name name) throws
+            NamingException {
         if (!name.isEmpty()) {
             throw (new InvalidNameException(
                     "RegistryContext: can only list \"\""));
@@ -228,11 +233,12 @@
         }
     }
 
-    public NamingEnumeration list(String name) throws NamingException {
+    public NamingEnumeration<NameClassPair> list(String name) throws
+            NamingException {
         return list(new CompositeName(name));
     }
 
-    public NamingEnumeration listBindings(Name name)
+    public NamingEnumeration<Binding> listBindings(Name name)
             throws NamingException
     {
         if (!name.isEmpty()) {
@@ -247,7 +253,8 @@
         }
     }
 
-    public NamingEnumeration listBindings(String name) throws NamingException {
+    public NamingEnumeration<Binding> listBindings(String name) throws
+            NamingException {
         return listBindings(new CompositeName(name));
     }
 
@@ -310,8 +317,9 @@
         return environment.put(propName, propVal);
     }
 
-    public Hashtable getEnvironment() throws NamingException {
-        return (Hashtable)environment.clone();
+    @SuppressWarnings("unchecked") // clone()
+    public Hashtable<String, Object> getEnvironment() throws NamingException {
+        return (Hashtable<String, Object>)environment.clone();
     }
 
     public void close() {
@@ -524,11 +532,9 @@
 
 
 /**
- * An enumeration of name / class-name pairs.  Since we don't know anything
- * about the classes, each class name is returned as the generic
- * "java.lang.Object".
+ * An enumeration of name / class-name pairs.
  */
-class NameClassPairEnumeration implements NamingEnumeration {
+class NameClassPairEnumeration implements NamingEnumeration<NameClassPair> {
     private final String[] names;
     private int nextName;       // index into "names"
 
@@ -541,7 +547,7 @@
         return (nextName < names.length);
     }
 
-    public Object next() throws NamingException {
+    public NameClassPair next() throws NamingException {
         if (!hasMore()) {
             throw (new java.util.NoSuchElementException());
         }
@@ -559,7 +565,7 @@
         return hasMore();
     }
 
-    public Object nextElement() {
+    public NameClassPair nextElement() {
         try {
             return next();
         } catch (NamingException e) {   // should never happen
@@ -582,7 +588,7 @@
  * requested.  The problem with that approach is that Binding.getObject()
  * cannot throw NamingException.
  */
-class BindingEnumeration implements NamingEnumeration {
+class BindingEnumeration implements NamingEnumeration<Binding> {
     private RegistryContext ctx;
     private final String[] names;
     private int nextName;       // index into "names"
@@ -605,7 +611,7 @@
         return (nextName < names.length);
     }
 
-    public Object next() throws NamingException {
+    public Binding next() throws NamingException {
         if (!hasMore()) {
             throw (new java.util.NoSuchElementException());
         }
@@ -625,7 +631,7 @@
         return hasMore();
     }
 
-    public Object nextElement() {
+    public Binding nextElement() {
         try {
             return next();
         } catch (NamingException e) {
--- a/src/share/classes/com/sun/jndi/rmi/registry/RegistryContextFactory.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/rmi/registry/RegistryContextFactory.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -95,7 +95,7 @@
         return obj;
     }
 
-    private static Context URLToContext(String url, Hashtable env)
+    private static Context URLToContext(String url, Hashtable<?,?> env)
             throws NamingException
     {
         rmiURLContextFactory factory = new rmiURLContextFactory();
@@ -108,7 +108,7 @@
         }
     }
 
-    private static Object URLsToObject(String[] urls, Hashtable env)
+    private static Object URLsToObject(String[] urls, Hashtable<?,?> env)
             throws NamingException
     {
         rmiURLContextFactory factory = new rmiURLContextFactory();
@@ -119,7 +119,7 @@
      * Reads environment to find URL of initial context.
      * The default URL is "rmi:".
      */
-    private static String getInitCtxURL(Hashtable env) {
+    private static String getInitCtxURL(Hashtable<?,?> env) {
 
         final String defaultURL = "rmi:";
 
@@ -152,9 +152,9 @@
         int size = 0;   // number of URLs
         String[] urls = new String[ref.size()];
 
-        Enumeration addrs = ref.getAll();
+        Enumeration<RefAddr> addrs = ref.getAll();
         while (addrs.hasMoreElements()) {
-            RefAddr addr = (RefAddr)addrs.nextElement();
+            RefAddr addr = addrs.nextElement();
 
             if ((addr instanceof StringRefAddr) &&
                 addr.getType().equals(ADDRESS_TYPE)) {
--- a/src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -159,7 +159,7 @@
      *               Use all String properties from env for initializing ORB
      * @return A non-null ORB.
      */
-    public static ORB getOrb(String server, int port, Hashtable env) {
+    public static ORB getOrb(String server, int port, Hashtable<?,?> env) {
         // See if we can get info from environment
         Properties orbProp;
 
@@ -170,7 +170,7 @@
                 orbProp = (Properties) env.clone();
             } else {
                 // Get all String properties
-                Enumeration envProp;
+                Enumeration<?> envProp;
                 orbProp = new Properties();
                 for (envProp = env.keys(); envProp.hasMoreElements();) {
                     String key = (String)envProp.nextElement();
@@ -266,7 +266,7 @@
     // Fields used for reflection of RMI-IIOP
     private static Method toStubMethod = null;
     private static Method connectMethod = null;
-    private static Class corbaStubClass = null;
+    private static Class<?> corbaStubClass = null;
     /**
      * Initializes reflection method handles for RMI-IIOP.
      * @exception ClassNotFoundException javax.rmi.CORBA.* not available
@@ -279,19 +279,19 @@
 
         try {
             connectMethod = corbaStubClass.getMethod("connect",
-                new Class[] {org.omg.CORBA.ORB.class});
+                new Class<?>[] {org.omg.CORBA.ORB.class});
         } catch (NoSuchMethodException e) {
             throw new IllegalStateException(
         "No method definition for javax.rmi.CORBA.Stub.connect(org.omg.CORBA.ORB)");
         }
 
-        // Get javax.rmi.PortableRemoteObject method
-        Class proClass = Class.forName("javax.rmi.PortableRemoteObject");
+        // Get javax.rmi.PortableRemoteObject class
+        Class<?> proClass = Class.forName("javax.rmi.PortableRemoteObject");
 
-        // Get javax.rmi.PortableRemoteObject(java.rmi.Remote) method
+        // Get javax.rmi.PortableRemoteObject.toStub(java.rmi.Remote) method
         try {
             toStubMethod = proClass.getMethod("toStub",
-                new Class[] {java.rmi.Remote.class});
+                new Class<?>[] {java.rmi.Remote.class});
 
         } catch (NoSuchMethodException e) {
             throw new IllegalStateException(
--- a/src/share/classes/com/sun/jndi/toolkit/ctx/AtomicContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/ctx/AtomicContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
 package com.sun.jndi.toolkit.ctx;
 
 import javax.naming.*;
-import javax.naming.spi.ResolveResult;
 
 /**
   * Clients: deal only with names for its own naming service
@@ -58,9 +57,9 @@
     protected abstract Object a_lookupLink(String name, Continuation cont)
         throws NamingException;
 
-    protected abstract NamingEnumeration a_list(
+    protected abstract NamingEnumeration<NameClassPair> a_list(
         Continuation cont) throws NamingException;
-    protected abstract NamingEnumeration a_listBindings(
+    protected abstract NamingEnumeration<Binding> a_listBindings(
         Continuation cont) throws NamingException;
     protected abstract void a_bind(String name, Object obj, Continuation cont)
         throws NamingException;
@@ -193,12 +192,12 @@
             return null;
         }
 
-    protected NamingEnumeration a_list_nns(Continuation cont)
+    protected NamingEnumeration<NameClassPair> a_list_nns(Continuation cont)
         throws NamingException {
             a_processJunction_nns(cont);
             return null;
         }
-    protected NamingEnumeration a_listBindings_nns(Continuation cont)
+    protected NamingEnumeration<Binding> a_listBindings_nns(Continuation cont)
         throws NamingException {
             a_processJunction_nns(cont);
             return null;
@@ -273,7 +272,7 @@
             return null;
         }
 
-    protected NamingEnumeration c_list(Name name,
+    protected NamingEnumeration<NameClassPair> c_list(Name name,
         Continuation cont) throws NamingException {
             if (resolve_to_context(name, cont)) {
                 return a_list(cont);
@@ -281,7 +280,7 @@
             return null;
         }
 
-    protected NamingEnumeration c_listBindings(Name name,
+    protected NamingEnumeration<Binding> c_listBindings(Name name,
         Continuation cont) throws NamingException {
             if (resolve_to_context(name, cont)) {
                 return a_listBindings(cont);
@@ -392,7 +391,7 @@
             }
         }
 
-    protected NamingEnumeration c_list_nns(Name name,
+    protected NamingEnumeration<NameClassPair> c_list_nns(Name name,
         Continuation cont) throws NamingException {
             if (_contextType == _ATOMIC) {
                 resolve_to_nns_and_continue(name, cont);
@@ -403,14 +402,14 @@
             }
         }
 
-    protected NamingEnumeration c_listBindings_nns(Name name,
+    protected NamingEnumeration<Binding> c_listBindings_nns(Name name,
         Continuation cont) throws NamingException {
             if (_contextType == _ATOMIC) {
                 resolve_to_nns_and_continue(name, cont);
                 return null;
             } else {
                 // use ComponentContext
-                return super.c_list_nns(name, cont);
+                return super.c_listBindings_nns(name, cont);
             }
         }
 
--- a/src/share/classes/com/sun/jndi/toolkit/ctx/AtomicDirContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/ctx/AtomicDirContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,6 @@
 
 import javax.naming.*;
 import javax.naming.directory.*;
-import javax.naming.spi.ResolveResult;
 
 /**
  * Direct subclasses of AtomicDirContext must provide implementations for
@@ -79,20 +78,25 @@
                                                     Continuation cont)
         throws NamingException;
 
-    protected abstract NamingEnumeration a_search(Attributes matchingAttributes,
+    protected abstract NamingEnumeration<SearchResult> a_search(
+                                                  Attributes matchingAttributes,
                                                   String[] attributesToReturn,
                                                   Continuation cont)
         throws NamingException;
 
-    protected abstract NamingEnumeration a_search(String name,
+    protected abstract NamingEnumeration<SearchResult> a_search(
+                                                  String name,
                                                   String filterExpr,
                                                   Object[] filterArgs,
-                                                  SearchControls cons, Continuation cont)
+                                                  SearchControls cons,
+                                                  Continuation cont)
         throws NamingException;
 
-    protected abstract NamingEnumeration a_search(String name,
+    protected abstract NamingEnumeration<SearchResult> a_search(
+                                                  String name,
                                                   String filter,
-                                                  SearchControls cons, Continuation cont)
+                                                  SearchControls cons,
+                                                  Continuation cont)
         throws NamingException;
 
     protected abstract DirContext a_getSchema(Continuation cont)
@@ -163,7 +167,8 @@
             return null;
         }
 
-    protected NamingEnumeration a_search_nns(Attributes matchingAttributes,
+    protected NamingEnumeration<SearchResult> a_search_nns(
+                                             Attributes matchingAttributes,
                                              String[] attributesToReturn,
                                              Continuation cont)
         throws NamingException {
@@ -171,20 +176,20 @@
             return null;
         }
 
-    protected NamingEnumeration a_search_nns(String name,
-                                             String filterExpr,
-                                             Object[] filterArgs,
-                                             SearchControls cons,
-                                             Continuation cont)
+    protected NamingEnumeration<SearchResult> a_search_nns(String name,
+                                                           String filterExpr,
+                                                           Object[] filterArgs,
+                                                           SearchControls cons,
+                                                           Continuation cont)
         throws NamingException {
             a_processJunction_nns(name, cont);
             return null;
         }
 
-    protected NamingEnumeration a_search_nns(String name,
-                                             String filter,
-                                             SearchControls cons,
-                                             Continuation cont)
+    protected NamingEnumeration<SearchResult> a_search_nns(String name,
+                                                           String filter,
+                                                           SearchControls cons,
+                                                           Continuation cont)
         throws NamingException  {
             a_processJunction_nns(name, cont);
             return null;
@@ -250,7 +255,7 @@
             return null;
         }
 
-    protected NamingEnumeration c_search(Name name,
+    protected NamingEnumeration<SearchResult> c_search(Name name,
                                          Attributes matchingAttributes,
                                          String[] attributesToReturn,
                                          Continuation cont)
@@ -260,19 +265,21 @@
             return null;
         }
 
-    protected NamingEnumeration c_search(Name name,
-                                         String filter,
-                                         SearchControls cons, Continuation cont)
+    protected NamingEnumeration<SearchResult> c_search(Name name,
+                                                       String filter,
+                                                       SearchControls cons,
+                                                       Continuation cont)
         throws NamingException {
             if (resolve_to_penultimate_context(name, cont))
                 return a_search(name.toString(), filter, cons, cont);
             return null;
         }
 
-    protected NamingEnumeration c_search(Name name,
-                                         String filterExpr,
-                                         Object[] filterArgs,
-                                         SearchControls cons, Continuation cont)
+    protected NamingEnumeration<SearchResult> c_search(Name name,
+                                                       String filterExpr,
+                                                       Object[] filterArgs,
+                                                       SearchControls cons,
+                                                       Continuation cont)
         throws NamingException  {
             if (resolve_to_penultimate_context(name, cont))
                 return a_search(name.toString(), filterExpr, filterArgs, cons, cont);
@@ -340,7 +347,8 @@
             return null;
         }
 
-    protected NamingEnumeration c_search_nns(Name name,
+    protected NamingEnumeration<SearchResult> c_search_nns(
+                                         Name name,
                                          Attributes matchingAttributes,
                                          String[] attributesToReturn,
                                          Continuation cont)
@@ -349,20 +357,21 @@
             return null;
         }
 
-    protected NamingEnumeration c_search_nns(Name name,
-                                         String filter,
-                                         SearchControls cons, Continuation cont)
+    protected NamingEnumeration<SearchResult> c_search_nns(Name name,
+                                                           String filter,
+                                                           SearchControls cons,
+                                                           Continuation cont)
         throws NamingException {
             if (resolve_to_penultimate_context_nns(name, cont))
                 return a_search_nns(name.toString(), filter, cons, cont);
             return null;
         }
 
-    protected NamingEnumeration c_search_nns(Name name,
-                                             String filterExpr,
-                                             Object[] filterArgs,
-                                             SearchControls cons,
-                                             Continuation cont)
+    protected NamingEnumeration<SearchResult> c_search_nns(Name name,
+                                                           String filterExpr,
+                                                           Object[] filterArgs,
+                                                           SearchControls cons,
+                                                           Continuation cont)
         throws NamingException  {
             if (resolve_to_penultimate_context_nns(name, cont))
                 return a_search_nns(name.toString(), filterExpr, filterArgs,
--- a/src/share/classes/com/sun/jndi/toolkit/ctx/ComponentContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/ctx/ComponentContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,6 @@
 
 package com.sun.jndi.toolkit.ctx;
 
-import java.util.Hashtable;
-
 import javax.naming.*;
 import javax.naming.spi.ResolveResult;
 
@@ -57,9 +55,9 @@
     protected abstract Object c_lookupLink(Name name, Continuation cont)
         throws NamingException;
 
-    protected abstract NamingEnumeration c_list(Name name,
+    protected abstract NamingEnumeration<NameClassPair> c_list(Name name,
         Continuation cont) throws NamingException;
-    protected abstract NamingEnumeration c_listBindings(Name name,
+    protected abstract NamingEnumeration<Binding> c_listBindings(Name name,
         Continuation cont) throws NamingException;
     protected abstract void c_bind(Name name, Object obj, Continuation cont)
         throws NamingException;
@@ -237,13 +235,13 @@
             return null;
         }
 
-    protected NamingEnumeration c_list_nns(Name name,
+    protected NamingEnumeration<NameClassPair> c_list_nns(Name name,
         Continuation cont) throws NamingException {
             c_processJunction_nns(name, cont);
             return null;
         }
 
-    protected NamingEnumeration c_listBindings_nns(Name name,
+    protected NamingEnumeration<Binding> c_listBindings_nns(Name name,
         Continuation cont) throws NamingException {
             c_processJunction_nns(name, cont);
             return null;
@@ -495,7 +493,7 @@
     /* implementation for Resolver method */
 
     protected ResolveResult p_resolveToClass(Name name,
-                                             Class contextType,
+                                             Class<?> contextType,
                                              Continuation cont)
             throws NamingException {
 
@@ -556,9 +554,9 @@
         return ret;
     }
 
-    protected NamingEnumeration p_list(Name name, Continuation cont)
+    protected NamingEnumeration<NameClassPair> p_list(Name name, Continuation cont)
         throws NamingException {
-        NamingEnumeration ret = null;
+        NamingEnumeration<NameClassPair> ret = null;
         HeadTail res = p_resolveIntermediate(name, cont);
         switch (res.getStatus()) {
             case TERMINAL_NNS_COMPONENT:
@@ -581,9 +579,9 @@
         return ret;
     }
 
-    protected NamingEnumeration p_listBindings(Name name, Continuation cont) throws
+    protected NamingEnumeration<Binding> p_listBindings(Name name, Continuation cont) throws
         NamingException {
-        NamingEnumeration ret = null;
+        NamingEnumeration<Binding> ret = null;
         HeadTail res = p_resolveIntermediate(name, cont);
         switch (res.getStatus()) {
             case TERMINAL_NNS_COMPONENT:
--- a/src/share/classes/com/sun/jndi/toolkit/ctx/ComponentDirContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/ctx/ComponentDirContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,8 +28,6 @@
 import javax.naming.*;
 import javax.naming.directory.*;
 
-import javax.naming.spi.ResolveResult;
-
 /* Direct subclasses of ComponentDirContext must provide implementations for
  * the abstract c_ DirContext methods, and override the c_ Context methods
  * (which are no longer abstract because they have been overriden by
@@ -81,23 +79,26 @@
                                                     Continuation cont)
         throws NamingException;
 
-    protected abstract NamingEnumeration c_search(Name name,
-                                               Attributes matchingAttributes,
-                                               String[] attributesToReturn,
-                                               Continuation cont)
+    protected abstract NamingEnumeration<SearchResult> c_search(
+                            Name name,
+                            Attributes matchingAttributes,
+                            String[] attributesToReturn,
+                            Continuation cont)
         throws NamingException;
 
-    protected abstract NamingEnumeration c_search(Name name,
-                                               String filter,
-                                               SearchControls cons,
-                                               Continuation cont)
+    protected abstract NamingEnumeration<SearchResult> c_search(
+                            Name name,
+                            String filter,
+                            SearchControls cons,
+                            Continuation cont)
         throws NamingException;
 
-    protected abstract NamingEnumeration c_search(Name name,
-                                                  String filterExpr,
-                                                  Object[] filterArgs,
-                                                  SearchControls cons,
-                                                  Continuation cont)
+    protected abstract NamingEnumeration<SearchResult> c_search(
+                            Name name,
+                            String filterExpr,
+                            Object[] filterArgs,
+                            SearchControls cons,
+                            Continuation cont)
         throws NamingException;
 
     protected abstract DirContext c_getSchema(Name name, Continuation cont)
@@ -172,29 +173,32 @@
             return null;
         }
 
-    protected NamingEnumeration c_search_nns(Name name,
-                                          Attributes matchingAttributes,
-                                          String[] attributesToReturn,
-                                          Continuation cont)
+    protected NamingEnumeration<SearchResult> c_search_nns(
+                        Name name,
+                        Attributes matchingAttributes,
+                        String[] attributesToReturn,
+                        Continuation cont)
         throws NamingException {
             c_processJunction_nns(name, cont);
             return null;
         }
 
-    protected NamingEnumeration c_search_nns(Name name,
-                                          String filter,
-                                          SearchControls cons,
-                                          Continuation cont)
+    protected NamingEnumeration<SearchResult> c_search_nns(
+                        Name name,
+                        String filter,
+                        SearchControls cons,
+                        Continuation cont)
         throws NamingException  {
             c_processJunction_nns(name, cont);
             return null;
         }
 
-    protected NamingEnumeration c_search_nns(Name name,
-                                             String filterExpr,
-                                             Object[] filterArgs,
-                                             SearchControls cons,
-                                             Continuation cont)
+    protected NamingEnumeration<SearchResult> c_search_nns(
+                        Name name,
+                        String filterExpr,
+                        Object[] filterArgs,
+                        SearchControls cons,
+                        Continuation cont)
         throws NamingException  {
             c_processJunction_nns(name, cont);
             return null;
@@ -345,13 +349,14 @@
         return answer;
     }
 
-    protected NamingEnumeration p_search(Name name,
-                                      Attributes matchingAttributes,
-                                      String[] attributesToReturn,
-                                      Continuation cont)
+    protected NamingEnumeration<SearchResult> p_search(
+                    Name name,
+                    Attributes matchingAttributes,
+                    String[] attributesToReturn,
+                    Continuation cont)
         throws NamingException {
         HeadTail res = p_resolveIntermediate(name, cont);
-        NamingEnumeration answer = null;
+        NamingEnumeration<SearchResult> answer = null;
         switch (res.getStatus()) {
             case TERMINAL_NNS_COMPONENT:
                 answer = c_search_nns(res.getHead(), matchingAttributes,
@@ -371,12 +376,13 @@
         return answer;
     }
 
-    protected NamingEnumeration p_search(Name name,
-                                      String filter,
-                                      SearchControls cons, Continuation cont)
+    protected NamingEnumeration<SearchResult> p_search(Name name,
+                                                       String filter,
+                                                       SearchControls cons,
+                                                       Continuation cont)
         throws NamingException {
         HeadTail res = p_resolveIntermediate(name, cont);
-        NamingEnumeration answer = null;
+        NamingEnumeration<SearchResult> answer = null;
         switch (res.getStatus()) {
             case TERMINAL_NNS_COMPONENT:
                 answer = c_search_nns(res.getHead(), filter, cons, cont);
@@ -394,14 +400,14 @@
         return answer;
     }
 
-    protected NamingEnumeration p_search(Name name,
-                                         String filterExpr,
-                                         Object[] filterArgs,
-                                         SearchControls cons,
-                                         Continuation cont)
+    protected NamingEnumeration<SearchResult> p_search(Name name,
+                                                       String filterExpr,
+                                                       Object[] filterArgs,
+                                                       SearchControls cons,
+                                                       Continuation cont)
             throws NamingException {
         HeadTail res = p_resolveIntermediate(name, cont);
-        NamingEnumeration answer = null;
+        NamingEnumeration<SearchResult> answer = null;
         switch (res.getStatus()) {
             case TERMINAL_NNS_COMPONENT:
                 answer = c_search_nns(res.getHead(),
--- a/src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java	Mon Jan 30 08:02:44 2017 +0000
@@ -57,7 +57,7 @@
      * The environment used by the caller. Initialized by constructor and
      * used when filling out a CannotProceedException.
      */
-    protected Hashtable environment = null;
+    protected Hashtable<?,?> environment = null;
 
     /**
      * Indicates whether the Continuation instance indicates that the operation
@@ -94,7 +94,7 @@
      * @param environment The environment used by the caller. It is used
      * when setting the "environment" of a CannotProceedException.
      */
-    public Continuation(Name top, Hashtable environment) {
+    public Continuation(Name top, Hashtable<?,?> environment) {
         super();
         starter = top;
         this.environment = environment;
@@ -154,8 +154,8 @@
 
         if ((e instanceof CannotProceedException)) {
             CannotProceedException cpe = (CannotProceedException)e;
-            Hashtable env = (environment == null ?
-                new Hashtable(11) : (Hashtable)environment.clone());
+            Hashtable<?,?> env = (environment == null ?
+                new Hashtable<>(11) : (Hashtable<?,?>)environment.clone());
             cpe.setEnvironment(env);
             cpe.setAltNameCtx(resolvedContext);
             cpe.setAltName(relativeResolvedName);
--- a/src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -77,16 +77,16 @@
 
     /* Equivalent to method in  Resolver interface */
     protected abstract ResolveResult p_resolveToClass(Name name,
-        Class contextType, Continuation cont) throws NamingException;
+        Class<?> contextType, Continuation cont) throws NamingException;
 
     /* Equivalent to methods in Context interface */
     protected abstract Object p_lookup(Name name, Continuation cont)
         throws NamingException;
     protected abstract Object p_lookupLink(Name name, Continuation cont)
         throws NamingException;
-    protected abstract NamingEnumeration p_list(Name name,
+    protected abstract NamingEnumeration<NameClassPair> p_list(Name name,
         Continuation cont) throws NamingException;
-    protected abstract NamingEnumeration p_listBindings(Name name,
+    protected abstract NamingEnumeration<Binding> p_listBindings(Name name,
         Continuation cont) throws NamingException;
     protected abstract void p_bind(Name name, Object obj, Continuation cont)
         throws NamingException;
@@ -115,7 +115,7 @@
      * The toolkit knows to clone when necessary.
      * @return The possibly null environment of the context.
      */
-    protected Hashtable p_getEnvironment() throws NamingException {
+    protected Hashtable<?,?> p_getEnvironment() throws NamingException {
         return getEnvironment();
     }
 
@@ -137,7 +137,7 @@
         throws NamingException
     {
         PartialCompositeContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         ResolveResult answer;
         Name nm = name;
@@ -168,7 +168,7 @@
 
     public Object lookup(Name name) throws NamingException {
         PartialCompositeContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         Object answer;
         Name nm = name;
@@ -194,7 +194,7 @@
     public void bind(Name name, Object newObj) throws NamingException {
         PartialCompositeContext ctx = this;
         Name nm = name;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
 
         try {
@@ -216,7 +216,7 @@
     public void rebind(Name name, Object newObj) throws NamingException {
         PartialCompositeContext ctx = this;
         Name nm = name;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
 
         try {
@@ -238,7 +238,7 @@
     public void unbind(Name name) throws NamingException {
         PartialCompositeContext ctx = this;
         Name nm = name;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
 
         try {
@@ -262,7 +262,7 @@
     {
         PartialCompositeContext ctx = this;
         Name nm = oldName;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(oldName, env);
 
         try {
@@ -293,8 +293,8 @@
     {
         PartialCompositeContext ctx = this;
         Name nm = name;
-        NamingEnumeration answer;
-        Hashtable env = p_getEnvironment();
+        NamingEnumeration<NameClassPair> answer;
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
 
         try {
@@ -322,8 +322,8 @@
     {
         PartialCompositeContext ctx = this;
         Name nm = name;
-        NamingEnumeration answer;
-        Hashtable env = p_getEnvironment();
+        NamingEnumeration<Binding> answer;
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
 
         try {
@@ -347,7 +347,7 @@
     public void destroySubcontext(Name name) throws NamingException {
         PartialCompositeContext ctx = this;
         Name nm = name;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
 
         try {
@@ -371,7 +371,7 @@
         PartialCompositeContext ctx = this;
         Name nm = name;
         Context answer;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
 
         try {
@@ -394,7 +394,7 @@
 
     public Object lookupLink(Name name) throws NamingException {
         PartialCompositeContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         Object answer;
         Name nm = name;
@@ -421,7 +421,7 @@
         PartialCompositeContext ctx = this;
         Name nm = name;
         NameParser answer;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
 
         try {
--- a/src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeDirContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeDirContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,6 @@
 
 import javax.naming.*;
 import javax.naming.directory.*;
-import javax.naming.spi.NamingManager;
 import javax.naming.spi.DirectoryManager;
 
 /*
@@ -83,23 +82,26 @@
                                                      Continuation cont)
          throws NamingException;
 
-     protected abstract NamingEnumeration p_search(Name name,
-                                                   Attributes matchingAttributes,
-                                                   String[] attributesToReturn,
-                                                   Continuation cont)
+     protected abstract NamingEnumeration<SearchResult> p_search(
+                            Name name,
+                            Attributes matchingAttributes,
+                            String[] attributesToReturn,
+                            Continuation cont)
          throws NamingException;
 
-     protected abstract NamingEnumeration p_search(Name name,
-                                                   String filter,
-                                                   SearchControls cons,
-                                                   Continuation cont)
+     protected abstract NamingEnumeration<SearchResult> p_search(
+                            Name name,
+                            String filter,
+                            SearchControls cons,
+                            Continuation cont)
          throws NamingException;
 
-     protected abstract NamingEnumeration p_search(Name name,
-                                                   String filterExpr,
-                                                   Object[] filterArgs,
-                                                   SearchControls cons,
-                                                   Continuation cont)
+     protected abstract NamingEnumeration<SearchResult> p_search(
+                            Name name,
+                            String filterExpr,
+                            Object[] filterArgs,
+                            SearchControls cons,
+                            Continuation cont)
          throws NamingException;
 
      protected abstract DirContext p_getSchema(Name name, Continuation cont)
@@ -130,7 +132,7 @@
     public Attributes getAttributes(Name name, String[] attrIds)
             throws NamingException {
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         Attributes answer;
         Name nm = name;
@@ -157,7 +159,7 @@
     public void modifyAttributes(Name name, int mod_op, Attributes attrs)
             throws NamingException {
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         Name nm = name;
 
@@ -182,7 +184,7 @@
     public void modifyAttributes(Name name, ModificationItem[] mods)
             throws NamingException {
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         Name nm = name;
 
@@ -207,7 +209,7 @@
     public void bind(Name name, Object obj, Attributes attrs)
             throws NamingException {
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         Name nm = name;
 
@@ -232,7 +234,7 @@
     public void rebind(Name name, Object obj, Attributes attrs)
             throws NamingException {
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         Name nm = name;
 
@@ -257,7 +259,7 @@
     public DirContext createSubcontext(Name name, Attributes attrs)
             throws NamingException {
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         DirContext answer;
         Name nm = name;
@@ -308,9 +310,9 @@
     {
 
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
-        NamingEnumeration answer;
+        NamingEnumeration<SearchResult> answer;
         Name nm = name;
 
         try {
@@ -347,9 +349,9 @@
     {
 
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
-        NamingEnumeration answer;
+        NamingEnumeration<SearchResult> answer;
         Name nm = name;
 
         try {
@@ -385,9 +387,9 @@
     {
 
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
-        NamingEnumeration answer;
+        NamingEnumeration<SearchResult> answer;
         Name nm = name;
 
         try {
@@ -411,7 +413,7 @@
 
     public DirContext getSchema(Name name) throws NamingException {
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         DirContext answer;
         Name nm = name;
@@ -438,7 +440,7 @@
     public DirContext getSchemaClassDefinition(Name name)
             throws NamingException {
         PartialCompositeDirContext ctx = this;
-        Hashtable env = p_getEnvironment();
+        Hashtable<?,?> env = p_getEnvironment();
         Continuation cont = new Continuation(name, env);
         DirContext answer;
         Name nm = name;
@@ -509,14 +511,14 @@
             throw cont.fillInException(e);
         }
 
-    protected NamingEnumeration a_list(
+    protected NamingEnumeration<NameClassPair> a_list(
         Continuation cont) throws NamingException {
             OperationNotSupportedException e = new
                 OperationNotSupportedException();
             throw cont.fillInException(e);
         }
 
-    protected NamingEnumeration a_listBindings(
+    protected NamingEnumeration<Binding> a_listBindings(
         Continuation cont) throws NamingException {
             OperationNotSupportedException e = new
                 OperationNotSupportedException();
--- a/src/share/classes/com/sun/jndi/toolkit/dir/ContainmentFilter.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/dir/ContainmentFilter.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -56,19 +56,19 @@
           if (subset == null)
             return true;  // an empty set is always a subset
 
-            NamingEnumeration m = subset.getAll();
+            NamingEnumeration<? extends Attribute> m = subset.getAll();
             while (m.hasMore()) {
                 if (superset == null) {
                     return false;  // contains nothing
                 }
-                Attribute target = (Attribute) m.next();
+                Attribute target = m.next();
                 Attribute fromSuper = superset.get(target.getID());
                 if (fromSuper == null) {
                     return false;
                 } else {
                     // check whether attribute values match
                     if (target.size() > 0) {
-                        NamingEnumeration vals = target.getAll();
+                        NamingEnumeration<?> vals = target.getAll();
                         while (vals.hasMore()) {
                             if (!fromSuper.contains(vals.next())) {
                                 return false;
--- a/src/share/classes/com/sun/jndi/toolkit/dir/ContextEnumerator.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/dir/ContextEnumerator.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,10 +33,10 @@
   *
   * @author Jon Ruiz
   */
-public class ContextEnumerator implements NamingEnumeration {
+public class ContextEnumerator implements NamingEnumeration<Binding> {
 
     private static boolean debug = false;
-    private NamingEnumeration children = null;
+    private NamingEnumeration<Binding> children = null;
     private Binding currentChild = null;
     private boolean currentReturned = false;
     private Context root;
@@ -77,7 +77,7 @@
     }
 
     // Subclass should override if it wants to avoid calling obj factory
-    protected NamingEnumeration getImmediateChildren(Context ctx)
+    protected NamingEnumeration<Binding> getImmediateChildren(Context ctx)
         throws NamingException {
             return ctx.listBindings("");
     }
@@ -101,7 +101,7 @@
         }
     }
 
-    public Object nextElement() {
+    public Binding nextElement() {
         try {
             return next();
         } catch (NamingException e) {
@@ -109,7 +109,7 @@
         }
     }
 
-    public Object next() throws NamingException {
+    public Binding next() throws NamingException {
         if (!rootProcessed) {
             rootProcessed = true;
             return new Binding("", root.getClass().getName(),
@@ -132,7 +132,7 @@
     }
 
     private Binding getNextChild() throws NamingException {
-        Binding oldBinding = ((Binding)children.next());
+        Binding oldBinding = children.next();
         Binding newBinding = null;
 
         // if the name is relative, we need to add it to the name of this
@@ -192,7 +192,7 @@
             if(debug) {System.out.println("getNextDescedant: expanded case");}
 
             // if the current child is expanded, use it's enumerator
-            return (Binding)currentChildEnum.next();
+            return currentChildEnum.next();
 
         } else {
 
--- a/src/share/classes/com/sun/jndi/toolkit/dir/DirSearch.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/dir/DirSearch.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,7 @@
   * @author Jon Ruiz
   */
 public class DirSearch {
-   public static NamingEnumeration search(DirContext ctx,
+   public static NamingEnumeration<SearchResult> search(DirContext ctx,
        Attributes matchingAttributes,
        String[] attributesToReturn) throws NamingException {
         SearchControls cons = new SearchControls(
@@ -48,7 +48,7 @@
             cons);
     }
 
-    public static NamingEnumeration search(DirContext ctx,
+    public static NamingEnumeration<SearchResult> search(DirContext ctx,
         String filter, SearchControls cons) throws NamingException {
 
         if (cons == null)
@@ -60,7 +60,7 @@
             cons);
     }
 
-    public static NamingEnumeration search(DirContext ctx,
+    public static NamingEnumeration<SearchResult> search(DirContext ctx,
         String filterExpr, Object[] filterArgs, SearchControls cons)
         throws NamingException {
 
--- a/src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,8 +42,8 @@
     static private final boolean debug = false;
     private static final NameParser defaultParser = new HierarchicalNameParser();
 
-    protected Hashtable myEnv;
-    protected Hashtable bindings;
+    protected Hashtable<String, Object> myEnv;
+    protected Hashtable<Name, Object> bindings;
     protected Attributes attrs;
     protected boolean ignoreCase = false;
     protected NamingException readOnlyEx = null;
@@ -70,12 +70,12 @@
         this(null, ignoreCase, false);
     }
 
-    public HierMemDirCtx(Hashtable environment, boolean ignoreCase) {
+    public HierMemDirCtx(Hashtable<String, Object> environment, boolean ignoreCase) {
         this(environment, ignoreCase, false);
     }
 
-    protected HierMemDirCtx(Hashtable environment, boolean ignoreCase,
-        boolean useFac) {
+    protected HierMemDirCtx(Hashtable<String, Object> environment,
+        boolean ignoreCase, boolean useFac) {
         myEnv = environment;
         this.ignoreCase = ignoreCase;
         init();
@@ -84,7 +84,7 @@
 
     private void init() {
         attrs = new BasicAttributes(ignoreCase);
-        bindings = new Hashtable(11, 0.75f);
+        bindings = new Hashtable<>(11, 0.75f);
     }
 
     public Object lookup(String name) throws NamingException {
@@ -326,30 +326,30 @@
         bindings.put(newname, oldBinding);
     }
 
-    public NamingEnumeration list(String name) throws NamingException {
+    public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
         return list(myParser.parse(name));
     }
 
-    public NamingEnumeration list(Name name) throws NamingException {
+    public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
         HierMemDirCtx ctx = (HierMemDirCtx) doLookup(name, false);
         return ctx.doList();
     }
 
-    protected NamingEnumeration doList () throws NamingException {
+    protected NamingEnumeration<NameClassPair> doList () throws NamingException {
         return new FlatNames(bindings.keys());
     }
 
 
-    public NamingEnumeration listBindings(String name) throws NamingException {
+    public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
         return listBindings(myParser.parse(name));
     }
 
-    public NamingEnumeration listBindings(Name name) throws NamingException {
+    public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
         HierMemDirCtx ctx = (HierMemDirCtx)doLookup(name, false);
         return ctx.doListBindings(alwaysUseFactory);
     }
 
-    protected NamingEnumeration doListBindings(boolean useFactory)
+    protected NamingEnumeration<Binding> doListBindings(boolean useFactory)
         throws NamingException {
         return new FlatBindings(bindings, myEnv, useFactory);
     }
@@ -447,28 +447,32 @@
         return result;
     }
 
+    @SuppressWarnings("unchecked") // clone()
     public Object addToEnvironment(String propName, Object propVal)
             throws NamingException {
-        myEnv = (myEnv == null) ?
-            new Hashtable(11, 0.75f) : (Hashtable)myEnv.clone();
+        myEnv = (myEnv == null)
+                ? new Hashtable<String, Object>(11, 0.75f)
+                : (Hashtable<String, Object>)myEnv.clone();
 
         return myEnv.put(propName, propVal);
     }
 
+    @SuppressWarnings("unchecked") // clone()
     public Object removeFromEnvironment(String propName)
             throws NamingException {
         if (myEnv == null)
             return null;
 
-        myEnv = (Hashtable)myEnv.clone();
+        myEnv = (Hashtable<String, Object>)myEnv.clone();
         return myEnv.remove(propName);
     }
 
-    public Hashtable getEnvironment() throws NamingException {
+    @SuppressWarnings("unchecked") // clone()
+    public Hashtable<String, Object> getEnvironment() throws NamingException {
         if (myEnv == null) {
-            return new Hashtable(5, 0.75f);
+            return new Hashtable<>(5, 0.75f);
         } else {
-            return (Hashtable)myEnv.clone();
+            return (Hashtable<String, Object>)myEnv.clone();
         }
     }
 
@@ -529,10 +533,10 @@
         }
 
         // turn it into a modification Enumeration and pass it on
-        NamingEnumeration attrEnum = attrs.getAll();
+        NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll();
         ModificationItem[] mods = new ModificationItem[attrs.size()];
         for (int i = 0; i < mods.length && attrEnum.hasMoreElements(); i++) {
-            mods[i] = new ModificationItem(mod_op, (Attribute)attrEnum.next());
+            mods[i] = new ModificationItem(mod_op, attrEnum.next());
         }
 
         modifyAttributes(name, mods);
@@ -564,7 +568,7 @@
 
         ModificationItem mod;
         Attribute existingAttr, modAttr;
-        NamingEnumeration modVals;
+        NamingEnumeration<?> modVals;
 
         for (int i = 0; i < mods.length; i++) {
             mod = mods[i];
@@ -619,29 +623,29 @@
         return orig;
     }
 
-    public NamingEnumeration search(String name,
-                                    Attributes matchingAttributes)
+    public NamingEnumeration<SearchResult> search(String name,
+                                                  Attributes matchingAttributes)
         throws NamingException {
         return search(name, matchingAttributes, null);
     }
 
-    public NamingEnumeration search(Name name,
-                                    Attributes matchingAttributes)
+    public NamingEnumeration<SearchResult> search(Name name,
+                                                  Attributes matchingAttributes)
         throws NamingException {
             return search(name, matchingAttributes, null);
     }
 
-     public NamingEnumeration search(String name,
-                                    Attributes matchingAttributes,
-                                    String[] attributesToReturn)
+     public NamingEnumeration<SearchResult> search(String name,
+                                                   Attributes matchingAttributes,
+                                                   String[] attributesToReturn)
         throws NamingException {
         return search(myParser.parse(name), matchingAttributes,
             attributesToReturn);
     }
 
-     public NamingEnumeration search(Name name,
-                                    Attributes matchingAttributes,
-                                    String[] attributesToReturn)
+     public NamingEnumeration<SearchResult> search(Name name,
+                                                   Attributes matchingAttributes,
+                                                   String[] attributesToReturn)
          throws NamingException {
 
         HierMemDirCtx target = (HierMemDirCtx) doLookup(name, false);
@@ -656,9 +660,9 @@
             false); // alwaysUseFactory ignored because objReturnFlag == false
     }
 
-    public NamingEnumeration search(Name name,
-                                    String filter,
-                                    SearchControls cons)
+    public NamingEnumeration<SearchResult> search(Name name,
+                                                  String filter,
+                                                  SearchControls cons)
         throws NamingException {
         DirContext target = (DirContext) doLookup(name, false);
 
@@ -671,27 +675,27 @@
             cons, this, myEnv, alwaysUseFactory);
     }
 
-     public NamingEnumeration search(Name name,
-                                    String filterExpr,
-                                    Object[] filterArgs,
-                                    SearchControls cons)
+     public NamingEnumeration<SearchResult> search(Name name,
+                                                   String filterExpr,
+                                                   Object[] filterArgs,
+                                                   SearchControls cons)
             throws NamingException {
 
         String strfilter = SearchFilter.format(filterExpr, filterArgs);
         return search(name, strfilter, cons);
     }
 
-    public NamingEnumeration search(String name,
-                                    String filter,
-                                    SearchControls cons)
+    public NamingEnumeration<SearchResult> search(String name,
+                                                  String filter,
+                                                  SearchControls cons)
         throws NamingException {
         return search(myParser.parse(name), filter, cons);
     }
 
-    public NamingEnumeration search(String name,
-                                    String filterExpr,
-                                    Object[] filterArgs,
-                                    SearchControls cons)
+    public NamingEnumeration<SearchResult> search(String name,
+                                                  String filterExpr,
+                                                  Object[] filterArgs,
+                                                  SearchControls cons)
             throws NamingException {
         return search(myParser.parse(name), filterExpr, filterArgs, cons);
     }
@@ -761,15 +765,17 @@
         myParser = parser;
     }
 
-    // Class for enumerating name/class pairs
-    private class FlatNames implements NamingEnumeration {
-        Enumeration names;
+    /*
+     * Common base class for FlatNames and FlatBindings.
+     */
+    private abstract class BaseFlatNames<T> implements NamingEnumeration<T> {
+        Enumeration<Name> names;
 
-        FlatNames (Enumeration names) {
+        BaseFlatNames (Enumeration<Name> names) {
             this.names = names;
         }
 
-        public boolean hasMoreElements() {
+        public final boolean hasMoreElements() {
             try {
                 return hasMore();
             } catch (NamingException e) {
@@ -777,11 +783,11 @@
             }
         }
 
-        public boolean hasMore() throws NamingException {
+        public final boolean hasMore() throws NamingException {
             return names.hasMoreElements();
         }
 
-        public Object nextElement() {
+        public final T nextElement() {
             try {
                 return next();
             } catch (NamingException e) {
@@ -789,32 +795,45 @@
             }
         }
 
-        public Object next() throws NamingException {
-            Name name = (Name)names.nextElement();
-            String className = bindings.get(name).getClass().getName();
-            return new NameClassPair(name.toString(), className);
-        }
+        public abstract T next() throws NamingException;
 
-        public void close() {
+        public final void close() {
             names = null;
         }
     }
 
-   // Class for enumerating bindings
-    private final class FlatBindings extends FlatNames {
-        private Hashtable bds;
-        private Hashtable env;
+    // Class for enumerating name/class pairs
+    private final class FlatNames extends BaseFlatNames<NameClassPair> {
+        FlatNames (Enumeration<Name> names) {
+            super(names);
+        }
+
+        @Override
+        public NameClassPair next() throws NamingException {
+            Name name = names.nextElement();
+            String className = bindings.get(name).getClass().getName();
+            return new NameClassPair(name.toString(), className);
+        }
+    }
+
+    // Class for enumerating bindings
+    private final class FlatBindings extends BaseFlatNames<Binding> {
+        private Hashtable<Name, Object> bds;
+        private Hashtable<String, Object> env;
         private boolean useFactory;
 
-        FlatBindings(Hashtable bindings, Hashtable env, boolean useFactory) {
+        FlatBindings(Hashtable<Name, Object> bindings,
+                     Hashtable<String, Object> env,
+                     boolean useFactory) {
             super(bindings.keys());
             this.env = env;
             this.bds = bindings;
             this.useFactory = useFactory;
         }
 
-        public Object next() throws NamingException {
-            Name name = (Name)names.nextElement();
+        @Override
+        public Binding next() throws NamingException {
+            Name name = names.nextElement();
 
             HierMemDirCtx obj = (HierMemDirCtx)bds.get(name);
 
@@ -849,7 +868,7 @@
             super(context, scope, contextName, returnSelf);
         }
 
-        protected NamingEnumeration getImmediateChildren(Context ctx)
+        protected NamingEnumeration<Binding> getImmediateChildren(Context ctx)
             throws NamingException {
                 return ((HierMemDirCtx)ctx).doListBindings(false);
         }
@@ -872,14 +891,14 @@
 
     // Creates an empty name
     HierarchicalName() {
-        super(new Enumeration() {
-            public boolean hasMoreElements() {return false;}
-            public Object nextElement() {throw new NoSuchElementException();}
-        },
-            HierarchicalNameParser.mySyntax);
+        super(new Enumeration<String>() {
+                  public boolean hasMoreElements() {return false;}
+                  public String nextElement() {throw new NoSuchElementException();}
+              },
+              HierarchicalNameParser.mySyntax);
     }
 
-    HierarchicalName(Enumeration comps, Properties syntax) {
+    HierarchicalName(Enumeration<String> comps, Properties syntax) {
         super(comps, syntax);
     }
 
@@ -907,12 +926,12 @@
     }
 
     public Name getPrefix(int posn) {
-        Enumeration comps = super.getPrefix(posn).getAll();
+        Enumeration<String> comps = super.getPrefix(posn).getAll();
         return (new HierarchicalName(comps, mySyntax));
     }
 
     public Name getSuffix(int posn) {
-        Enumeration comps = super.getSuffix(posn).getAll();
+        Enumeration<String> comps = super.getSuffix(posn).getAll();
         return (new HierarchicalName(comps, mySyntax));
     }
 
--- a/src/share/classes/com/sun/jndi/toolkit/dir/LazySearchEnumerationImpl.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/dir/LazySearchEnumerationImpl.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -47,16 +47,17 @@
 import java.util.NoSuchElementException;
 import java.util.Hashtable;
 
-final public class LazySearchEnumerationImpl implements NamingEnumeration {
-    private NamingEnumeration candidates;
+final public class LazySearchEnumerationImpl
+        implements NamingEnumeration<SearchResult> {
+    private NamingEnumeration<Binding> candidates;
     private SearchResult nextMatch = null;
     private SearchControls cons;
     private AttrFilter filter;
     private Context context;
-    private Hashtable env;
+    private Hashtable<String, Object> env;
     private boolean useFactory = true;
 
-    public LazySearchEnumerationImpl(NamingEnumeration candidates,
+    public LazySearchEnumerationImpl(NamingEnumeration<Binding> candidates,
         AttrFilter filter, SearchControls cons) throws NamingException {
             this.candidates = candidates;
             this.filter = filter;
@@ -68,9 +69,10 @@
             }
     }
 
-    public LazySearchEnumerationImpl(NamingEnumeration candidates,
+    public LazySearchEnumerationImpl(NamingEnumeration<Binding> candidates,
         AttrFilter filter, SearchControls cons,
-        Context ctx, Hashtable env, boolean useFactory) throws NamingException {
+        Context ctx, Hashtable<String, Object> env, boolean useFactory)
+        throws NamingException {
 
             this.candidates = candidates;
             this.filter = filter;
@@ -86,9 +88,9 @@
     }
 
 
-    public LazySearchEnumerationImpl(NamingEnumeration candidates,
+    public LazySearchEnumerationImpl(NamingEnumeration<Binding> candidates,
         AttrFilter filter, SearchControls cons,
-        Context ctx, Hashtable env) throws NamingException {
+        Context ctx, Hashtable<String, Object> env) throws NamingException {
             this(candidates, filter, cons, ctx, env, true);
     }
 
@@ -105,7 +107,7 @@
         }
     }
 
-    public Object nextElement() {
+    public SearchResult nextElement() {
         try {
             return findNextMatch(true);
         } catch (NamingException e) {
@@ -113,7 +115,7 @@
         }
     }
 
-    public Object next() throws NamingException {
+    public SearchResult next() throws NamingException {
         // find and remove from list
         return (findNextMatch(true));
     }
@@ -138,7 +140,7 @@
             Object obj;
             Attributes targetAttrs;
             while (candidates.hasMore()) {
-                next = (Binding)candidates.next();
+                next = candidates.next();
                 obj = next.getObject();
                 if (obj instanceof DirContext) {
                     targetAttrs = ((DirContext)(obj)).getAttributes("");
--- a/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -203,11 +203,11 @@
      * A class for dealing with compound filters ("and" & "or" filters).
      */
     final class CompoundFilter implements StringFilter {
-        private Vector  subFilters;
+        private Vector<StringFilter>  subFilters;
         private boolean polarity;
 
         CompoundFilter(boolean polarity) {
-            subFilters = new Vector();
+            subFilters = new Vector<>();
             this.polarity = polarity;
         }
 
@@ -223,7 +223,7 @@
 
         public boolean check(Attributes targetAttrs) throws NamingException {
             for(int i = 0; i<subFilters.size(); i++) {
-                StringFilter filter = (StringFilter)subFilters.elementAt(i);
+                StringFilter filter = subFilters.elementAt(i);
                 if(filter.check(targetAttrs) != this.polarity) {
                     return !polarity;
                 }
@@ -330,7 +330,7 @@
         }
 
         public boolean check(Attributes targetAttrs) {
-            Enumeration candidates;
+            Enumeration<?> candidates;
 
             try {
                 Attribute attr = targetAttrs.get(attrID);
@@ -441,15 +441,15 @@
         String answer;
         answer = "(& ";
         Attribute attr;
-        for (NamingEnumeration e = attrs.getAll(); e.hasMore(); ) {
-            attr = (Attribute)e.next();
+        for (NamingEnumeration<? extends Attribute> e = attrs.getAll();
+             e.hasMore(); ) {
+            attr = e.next();
             if (attr.size() == 0 || (attr.size() == 1 && attr.get() == null)) {
                 // only checking presence of attribute
                 answer += "(" + attr.getID() + "=" + "*)";
             } else {
-                for (NamingEnumeration ve = attr.getAll();
-                     ve.hasMore();
-                        ) {
+                for (NamingEnumeration<?> ve = attr.getAll();
+                     ve.hasMore(); ) {
                     String val = getEncodedStringRep(ve.next());
                     if (val != null) {
                         answer += "(" + attr.getID() + "=" + val + ")";
--- a/src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,11 +48,12 @@
  * @author Rosanna Lee
  */
 abstract public class GenericURLContext implements Context {
-    protected Hashtable myEnv = null;
+    protected Hashtable<String, Object> myEnv = null;
 
-    public GenericURLContext(Hashtable env) {
+    @SuppressWarnings("unchecked") // Expect Hashtable<String, Object>
+    public GenericURLContext(Hashtable<?,?> env) {
         // context that is not tied to any specific URL
-        myEnv = env;  // copied on write
+        myEnv = (Hashtable<String, Object>)env;  // copied on write
     }
 
     public void close() throws NamingException {
@@ -75,7 +76,7 @@
       * must be in sync wrt how URLs are parsed and returned.
       */
     abstract protected ResolveResult getRootURLContext(String url,
-        Hashtable env) throws NamingException;
+        Hashtable<?,?> env) throws NamingException;
 
     /**
       * Returns the suffix of the url. The result should be identical to
@@ -487,27 +488,31 @@
         return result;
     }
 
+    @SuppressWarnings("unchecked") // clone()
     public Object removeFromEnvironment(String propName)
         throws NamingException {
             if (myEnv == null) {
                 return null;
             }
-            myEnv = (Hashtable)myEnv.clone();
+            myEnv = (Hashtable<String, Object>)myEnv.clone();
             return myEnv.remove(propName);
     }
 
+    @SuppressWarnings("unchecked") // clone()
     public Object addToEnvironment(String propName, Object propVal)
         throws NamingException {
-            myEnv = (myEnv == null) ?
-                new Hashtable(11, 0.75f) : (Hashtable)myEnv.clone();
+            myEnv = (myEnv == null)
+                    ? new Hashtable<String, Object>(11, 0.75f)
+                    : (Hashtable<String, Object>)myEnv.clone();
             return myEnv.put(propName, propVal);
     }
 
-    public Hashtable getEnvironment() throws NamingException {
+    @SuppressWarnings("unchecked") // clone()
+    public Hashtable<String, Object> getEnvironment() throws NamingException {
         if (myEnv == null) {
-            return new Hashtable(5, 0.75f);
+            return new Hashtable<>(5, 0.75f);
         } else {
-            return (Hashtable)myEnv.clone();
+            return (Hashtable<String, Object>)myEnv.clone();
         }
     }
 
--- a/src/share/classes/com/sun/jndi/toolkit/url/GenericURLDirContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/toolkit/url/GenericURLDirContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,7 +50,7 @@
 abstract public class GenericURLDirContext extends GenericURLContext
 implements DirContext {
 
-    protected GenericURLDirContext(Hashtable env) {
+    protected GenericURLDirContext(Hashtable<?,?> env) {
         super(env);
     }
 
--- a/src/share/classes/com/sun/jndi/url/dns/dnsURLContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/url/dns/dnsURLContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,7 @@
 
 public class dnsURLContext extends GenericURLDirContext {
 
-    public dnsURLContext(Hashtable env) {
+    public dnsURLContext(Hashtable<?,?> env) {
         super(env);
     }
 
@@ -54,7 +54,7 @@
      * to the named DNS server, and returns the domain name as the
      * remaining name.
      */
-    protected ResolveResult getRootURLContext(String url, Hashtable env)
+    protected ResolveResult getRootURLContext(String url, Hashtable<?,?> env)
             throws NamingException {
 
         DnsUrl dnsUrl;
--- a/src/share/classes/com/sun/jndi/url/dns/dnsURLContextFactory.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/url/dns/dnsURLContextFactory.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,7 +62,7 @@
         }
     }
 
-    private static Object getUsingURL(String url, Hashtable env)
+    private static Object getUsingURL(String url, Hashtable<?,?> env)
             throws NamingException {
 
         dnsURLContext urlCtx = new dnsURLContext(env);
@@ -78,7 +78,7 @@
      * If all URLs fail, throw one of the exceptions arbitrarily.
      * Not pretty, but potentially more informative than returning null.
      */
-    private static Object getUsingURLs(String[] urls, Hashtable env)
+    private static Object getUsingURLs(String[] urls, Hashtable<?,?> env)
             throws NamingException {
 
         if (urls.length == 0) {
--- a/src/share/classes/com/sun/jndi/url/iiop/iiopURLContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/url/iiop/iiopURLContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
 public class iiopURLContext
         extends com.sun.jndi.toolkit.url.GenericURLContext {
 
-    iiopURLContext(Hashtable env) {
+    iiopURLContext(Hashtable<?,?> env) {
         super(env);
     }
 
@@ -56,7 +56,7 @@
       * context on for the ORB at 'localhost' on port 900,
       * and returns as the remaining name "rest/of/name".
       */
-    protected ResolveResult getRootURLContext(String name, Hashtable env)
+    protected ResolveResult getRootURLContext(String name, Hashtable<?,?> env)
     throws NamingException {
         return iiopURLContextFactory.getUsingURLIgnoreRest(name, env);
     }
--- a/src/share/classes/com/sun/jndi/url/iiop/iiopURLContextFactory.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/url/iiop/iiopURLContextFactory.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -68,12 +68,12 @@
       * context on for the ORB at 'localhost' on port 900,
       * and returns as the remaining name "rest/of/name".
       */
-    static ResolveResult getUsingURLIgnoreRest(String url, Hashtable env)
+    static ResolveResult getUsingURLIgnoreRest(String url, Hashtable<?,?> env)
         throws NamingException {
         return CNCtx.createUsingURL(url, env);
     }
 
-    private static Object getUsingURL(String url, Hashtable env)
+    private static Object getUsingURL(String url, Hashtable<?,?> env)
         throws NamingException {
         ResolveResult res = getUsingURLIgnoreRest(url, env);
 
@@ -85,7 +85,7 @@
         }
     }
 
-    private static Object getUsingURLs(String[] urls, Hashtable env) {
+    private static Object getUsingURLs(String[] urls, Hashtable<?,?> env) {
         for (int i = 0; i < urls.length; i++) {
             String url = urls[i];
             try {
--- a/src/share/classes/com/sun/jndi/url/ldap/ldapURLContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/url/ldap/ldapURLContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
 final public class ldapURLContext
         extends com.sun.jndi.toolkit.url.GenericURLDirContext {
 
-    ldapURLContext(Hashtable env) {
+    ldapURLContext(Hashtable<?,?> env) {
         super(env);
     }
 
@@ -56,7 +56,7 @@
       * context on the server 'localhost' on port 389,
       * and returns as the remaining name "o=widget, c=us".
       */
-    protected ResolveResult getRootURLContext(String name, Hashtable env)
+    protected ResolveResult getRootURLContext(String name, Hashtable<?,?> env)
     throws NamingException {
         return ldapURLContextFactory.getUsingURLIgnoreRootDN(name, env);
     }
@@ -171,7 +171,8 @@
         }
     }
 
-    public NamingEnumeration list(String name)  throws NamingException {
+    public NamingEnumeration<NameClassPair> list(String name)
+            throws NamingException {
         if (LdapURL.hasQueryComponents(name)) {
             throw new InvalidNameException(name);
         } else {
@@ -179,7 +180,8 @@
         }
     }
 
-    public NamingEnumeration list(Name name) throws NamingException {
+    public NamingEnumeration<NameClassPair> list(Name name)
+            throws NamingException {
         if (LdapURL.hasQueryComponents(name.get(0))) {
             throw new InvalidNameException(name.toString());
         } else {
@@ -187,7 +189,8 @@
         }
     }
 
-    public NamingEnumeration listBindings(String name) throws NamingException {
+    public NamingEnumeration<Binding> listBindings(String name)
+            throws NamingException {
         if (LdapURL.hasQueryComponents(name)) {
             throw new InvalidNameException(name);
         } else {
@@ -195,7 +198,8 @@
         }
     }
 
-    public NamingEnumeration listBindings(Name name) throws NamingException {
+    public NamingEnumeration<Binding> listBindings(Name name)
+            throws NamingException {
         if (LdapURL.hasQueryComponents(name.get(0))) {
             throw new InvalidNameException(name.toString());
         } else {
@@ -447,7 +451,7 @@
     }
 
     // divert the search operation when the LDAP URL has query components
-    public NamingEnumeration search(String name,
+    public NamingEnumeration<SearchResult> search(String name,
         Attributes matchingAttributes)
         throws NamingException {
 
@@ -459,7 +463,7 @@
     }
 
     // divert the search operation when name has a single component
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
         Attributes matchingAttributes)
         throws NamingException {
         if (name.size() == 1) {
@@ -472,7 +476,7 @@
     }
 
     // divert the search operation when the LDAP URL has query components
-    public NamingEnumeration search(String name,
+    public NamingEnumeration<SearchResult> search(String name,
         Attributes matchingAttributes,
         String[] attributesToReturn)
         throws NamingException {
@@ -485,7 +489,7 @@
     }
 
     // divert the search operation when name has a single component
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
         Attributes matchingAttributes,
         String[] attributesToReturn)
         throws NamingException {
@@ -500,7 +504,7 @@
     }
 
     // divert the search operation when the LDAP URL has query components
-    public NamingEnumeration search(String name,
+    public NamingEnumeration<SearchResult> search(String name,
         String filter,
         SearchControls cons)
         throws NamingException {
@@ -513,7 +517,7 @@
     }
 
     // divert the search operation when name has a single component
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
         String filter,
         SearchControls cons)
         throws NamingException {
@@ -528,7 +532,7 @@
     }
 
     // divert the search operation when the LDAP URL has query components
-    public NamingEnumeration search(String name,
+    public NamingEnumeration<SearchResult> search(String name,
         String filterExpr,
         Object[] filterArgs,
         SearchControls cons)
@@ -542,7 +546,7 @@
     }
 
     // divert the search operation when name has a single component
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
         String filterExpr,
         Object[] filterArgs,
         SearchControls cons)
@@ -559,7 +563,7 @@
 
     // Search using the LDAP URL in name.
     // LDAP URL query components override the search argments.
-    private NamingEnumeration searchUsingURL(String name)
+    private NamingEnumeration<SearchResult> searchUsingURL(String name)
         throws NamingException {
 
         LdapURL url = new LdapURL(name);
--- a/src/share/classes/com/sun/jndi/url/ldap/ldapURLContextFactory.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/url/ldap/ldapURLContextFactory.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -53,7 +53,7 @@
         }
     }
 
-    static ResolveResult getUsingURLIgnoreRootDN(String url, Hashtable env)
+    static ResolveResult getUsingURLIgnoreRootDN(String url, Hashtable<?,?> env)
             throws NamingException {
         LdapURL ldapUrl = new LdapURL(url);
         DirContext ctx = new LdapCtx("", ldapUrl.getHost(), ldapUrl.getPort(),
--- a/src/share/classes/com/sun/jndi/url/rmi/rmiURLContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/url/rmi/rmiURLContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
 package com.sun.jndi.url.rmi;
 
 import java.util.Hashtable;
-import java.rmi.registry.LocateRegistry;
 
 import javax.naming.*;
 import javax.naming.spi.ResolveResult;
@@ -48,7 +47,7 @@
  */
 public class rmiURLContext extends GenericURLContext {
 
-    public rmiURLContext(Hashtable env) {
+    public rmiURLContext(Hashtable<?,?> env) {
         super(env);
     }
 
@@ -57,7 +56,7 @@
      * RMI registry, and returns the atomic object name as the
      * remaining name.
      */
-    protected ResolveResult getRootURLContext(String url, Hashtable env)
+    protected ResolveResult getRootURLContext(String url, Hashtable<?,?> env)
             throws NamingException
     {
         if (!url.startsWith("rmi:")) {
--- a/src/share/classes/com/sun/jndi/url/rmi/rmiURLContextFactory.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/jndi/url/rmi/rmiURLContextFactory.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -63,7 +63,7 @@
         }
     }
 
-    private static Object getUsingURL(String url, Hashtable env)
+    private static Object getUsingURL(String url, Hashtable<?,?> env)
             throws NamingException
     {
         rmiURLContext urlCtx = new rmiURLContext(env);
@@ -79,7 +79,7 @@
      * If all URLs fail, throw one of the exceptions arbitrarily.
      * Not pretty, but potentially more informative than returning null.
      */
-    private static Object getUsingURLs(String[] urls, Hashtable env)
+    private static Object getUsingURLs(String[] urls, Hashtable<?,?> env)
             throws NamingException
     {
         if (urls.length == 0) {
--- a/src/share/classes/com/sun/naming/internal/FactoryEnumeration.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/naming/internal/FactoryEnumeration.java	Mon Jan 30 08:02:44 2017 +0000
@@ -37,7 +37,8 @@
 
 // no need to implement Enumeration since this is only for internal use
 public final class FactoryEnumeration {
-    private List factories;
+    // List<NamedWeakReference<Class | Object>>
+    private List<NamedWeakReference<Object>> factories;
     private int posn = 0;
     private ClassLoader loader;
 
@@ -62,7 +63,8 @@
      * This internal method is used with Thread Context Class Loader (TCCL),
      * please don't expose this method as public.
      */
-    FactoryEnumeration(List factories, ClassLoader loader) {
+    FactoryEnumeration(List<NamedWeakReference<Object>> factories,
+                       ClassLoader loader) {
         this.factories = factories;
         this.loader = loader;
     }
@@ -70,7 +72,7 @@
     public Object next() throws NamingException {
         synchronized (factories) {
 
-            NamedWeakReference ref = (NamedWeakReference) factories.get(posn++);
+            NamedWeakReference<Object> ref = factories.get(posn++);
             Object answer = ref.get();
             if ((answer != null) && !(answer instanceof Class)) {
                 return answer;
@@ -85,7 +87,7 @@
                 }
                 // Instantiate Class to get factory
                 answer = ((Class) answer).newInstance();
-                ref = new NamedWeakReference(answer, className);
+                ref = new NamedWeakReference<>(answer, className);
                 factories.set(posn-1, ref);  // replace Class object or null
                 return answer;
             } catch (ClassNotFoundException e) {
--- a/src/share/classes/com/sun/naming/internal/NamedWeakReference.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/naming/internal/NamedWeakReference.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,11 +33,11 @@
  */
 
 
-class NamedWeakReference extends java.lang.ref.WeakReference {
+class NamedWeakReference<T> extends java.lang.ref.WeakReference<T> {
 
     private final String name;
 
-    NamedWeakReference(Object referent, String name) {
+    NamedWeakReference(T referent, String name) {
         super(referent);
         this.name = name;
     }
--- a/src/share/classes/com/sun/naming/internal/ResourceManager.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/naming/internal/ResourceManager.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,11 +27,9 @@
 
 import java.io.InputStream;
 import java.io.IOException;
-import java.net.URL;
 import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
@@ -97,7 +95,9 @@
      * One from application resource files is keyed on the thread's
      * context class loader.
      */
-    private static final WeakHashMap propertiesCache = new WeakHashMap(11);
+    // WeakHashMap<Class | ClassLoader, Hashtable>
+    private static final WeakHashMap<Object, Hashtable<? super String, Object>>
+            propertiesCache = new WeakHashMap<>(11);
 
     /*
      * A cache of factory objects (ObjectFactory, StateFactory, ControlFactory).
@@ -107,7 +107,9 @@
      * weakly referenced so as not to prevent GC of the class loader.
      * Used in getFactories().
      */
-    private static final WeakHashMap factoryCache = new WeakHashMap(11);
+    private static final
+        WeakHashMap<ClassLoader, Map<String, List<NamedWeakReference<Object>>>>
+            factoryCache = new WeakHashMap<>(11);
 
     /*
      * A cache of URL factory objects (ObjectFactory).
@@ -118,8 +120,11 @@
      * NO_FACTORY if a previous search revealed no factory.  Used in
      * getFactory().
      */
-    private static final WeakHashMap urlFactoryCache = new WeakHashMap(11);
-    private static final WeakReference NO_FACTORY = new WeakReference(null);
+    private static final
+        WeakHashMap<ClassLoader, Map<String, WeakReference<Object>>>
+            urlFactoryCache = new WeakHashMap<>(11);
+    private static final WeakReference<Object> NO_FACTORY =
+            new WeakReference<>(null);
 
     /**
      * A class to allow JNDI properties be specified as applet parameters
@@ -160,10 +165,9 @@
                 throw new ClassCastException(applet.getClass().getName());
             try {
                 return getMethod.invoke(applet, name);
-            } catch (InvocationTargetException e) {
+            } catch (InvocationTargetException |
+                     IllegalAccessException e) {
                 throw new AssertionError(e);
-            } catch (IllegalAccessException iae) {
-                throw new AssertionError(iae);
             }
         }
     }
@@ -191,12 +195,14 @@
      * @throws NamingException if an error occurs while reading a
      *          resource file
      */
-    public static Hashtable getInitialEnvironment(Hashtable env)
+    @SuppressWarnings("unchecked")
+    public static Hashtable<?, ?> getInitialEnvironment(
+            Hashtable<?, ?> env)
             throws NamingException
     {
         String[] props = VersionHelper.PROPS;   // system/applet properties
         if (env == null) {
-            env = new Hashtable(11);
+            env = new Hashtable<>(11);
         }
         Object applet = env.get(Context.APPLET);
 
@@ -221,7 +227,7 @@
                         : helper.getJndiProperty(i);
                 }
                 if (val != null) {
-                    env.put(props[i], val);
+                    ((Hashtable<String, Object>)env).put(props[i], val);
                 }
             }
         }
@@ -235,7 +241,7 @@
 
         // Merge the above with the values read from all application
         // resource files.  Colon-separated lists are concatenated.
-        mergeTables(env, getApplicationResources());
+        mergeTables((Hashtable<Object, Object>)env, getApplicationResources());
         return env;
     }
 
@@ -259,7 +265,7 @@
       * @throws NamingException if an error occurs while reading the provider
       * resource file.
       */
-    public static String getProperty(String propName, Hashtable env,
+    public static String getProperty(String propName, Hashtable<?,?> env,
         Context ctx, boolean concat)
             throws NamingException {
 
@@ -320,8 +326,8 @@
      * @see javax.naming.spi.DirectoryManager#getStateToBind
      * @see javax.naming.ldap.ControlFactory#getControlInstance
      */
-    public static FactoryEnumeration getFactories(String propName, Hashtable env,
-        Context ctx) throws NamingException {
+    public static FactoryEnumeration getFactories(String propName,
+        Hashtable<?,?> env, Context ctx) throws NamingException {
 
         String facProp = getProperty(propName, env, ctx, true);
         if (facProp == null)
@@ -330,17 +336,18 @@
         // Cache is based on context class loader and property val
         ClassLoader loader = helper.getContextClassLoader();
 
-        Map perLoaderCache = null;
+        Map<String, List<NamedWeakReference<Object>>> perLoaderCache = null;
         synchronized (factoryCache) {
-            perLoaderCache = (Map) factoryCache.get(loader);
+            perLoaderCache = factoryCache.get(loader);
             if (perLoaderCache == null) {
-                perLoaderCache = new HashMap(11);
+                perLoaderCache = new HashMap<>(11);
                 factoryCache.put(loader, perLoaderCache);
             }
         }
 
         synchronized (perLoaderCache) {
-            List factories = (List) perLoaderCache.get(facProp);
+            List<NamedWeakReference<Object>> factories =
+                    perLoaderCache.get(facProp);
             if (factories != null) {
                 // Cached list
                 return factories.size() == 0 ? null
@@ -349,13 +356,13 @@
                 // Populate list with classes named in facProp; skipping
                 // those that we cannot load
                 StringTokenizer parser = new StringTokenizer(facProp, ":");
-                factories = new ArrayList(5);
+                factories = new ArrayList<>(5);
                 while (parser.hasMoreTokens()) {
                     try {
                         // System.out.println("loading");
                         String className = parser.nextToken();
-                        Class c = helper.loadClass(className, loader);
-                        factories.add(new NamedWeakReference(c, className));
+                        Class<?> c = helper.loadClass(className, loader);
+                        factories.add(new NamedWeakReference<Object>(c, className));
                     } catch (Exception e) {
                         // ignore ClassNotFoundException, IllegalArgumentException
                     }
@@ -403,8 +410,9 @@
      * @see javax.naming.spi.NamingManager#getURLContext
      * @see javax.naming.spi.NamingManager#getURLObject
      */
-    public static Object getFactory(String propName, Hashtable env, Context ctx,
-        String classSuffix, String defaultPkgPrefix) throws NamingException {
+    public static Object getFactory(String propName, Hashtable<?,?> env,
+            Context ctx, String classSuffix, String defaultPkgPrefix)
+            throws NamingException {
 
         // Merge property with provider property and supplied default
         String facProp = getProperty(propName, env, ctx, true);
@@ -418,11 +426,11 @@
         ClassLoader loader = helper.getContextClassLoader();
         String key = classSuffix + " " + facProp;
 
-        Map perLoaderCache = null;
+        Map<String, WeakReference<Object>> perLoaderCache = null;
         synchronized (urlFactoryCache) {
-            perLoaderCache = (Map) urlFactoryCache.get(loader);
+            perLoaderCache = urlFactoryCache.get(loader);
             if (perLoaderCache == null) {
-                perLoaderCache = new HashMap(11);
+                perLoaderCache = new HashMap<>(11);
                 urlFactoryCache.put(loader, perLoaderCache);
             }
         }
@@ -430,7 +438,7 @@
         synchronized (perLoaderCache) {
             Object factory = null;
 
-            WeakReference factoryRef = (WeakReference) perLoaderCache.get(key);
+            WeakReference<Object> factoryRef = perLoaderCache.get(key);
             if (factoryRef == NO_FACTORY) {
                 return null;
             } else if (factoryRef != null) {
@@ -466,7 +474,7 @@
 
             // Cache it.
             perLoaderCache.put(key, (factory != null)
-                                        ? new WeakReference(factory)
+                                        ? new WeakReference<>(factory)
                                         : NO_FACTORY);
             return factory;
         }
@@ -483,16 +491,18 @@
      *
      * @throws NamingException if an error occurs while reading the file.
      */
-    private static Hashtable getProviderResource(Object obj)
+    private static Hashtable<? super String, Object>
+        getProviderResource(Object obj)
             throws NamingException
     {
         if (obj == null) {
-            return (new Hashtable(1));
+            return (new Hashtable<>(1));
         }
         synchronized (propertiesCache) {
-            Class c = obj.getClass();
+            Class<?> c = obj.getClass();
 
-            Hashtable props = (Hashtable)propertiesCache.get(c);
+            Hashtable<? super String, Object> props =
+                    propertiesCache.get(c);
             if (props != null) {
                 return props;
             }
@@ -533,22 +543,23 @@
      * @throws NamingException if an error occurs while reading a resource
      *  file.
      */
-    private static Hashtable getApplicationResources() throws NamingException {
+    private static Hashtable<? super String, Object> getApplicationResources()
+            throws NamingException {
 
         ClassLoader cl = helper.getContextClassLoader();
 
         synchronized (propertiesCache) {
-            Hashtable result = (Hashtable)propertiesCache.get(cl);
+            Hashtable<? super String, Object> result = propertiesCache.get(cl);
             if (result != null) {
                 return result;
             }
 
             try {
-                NamingEnumeration resources =
+                NamingEnumeration<InputStream> resources =
                     helper.getResources(cl, APP_RESOURCE_FILE_NAME);
                 while (resources.hasMore()) {
                     Properties props = new Properties();
-                    props.load((InputStream)resources.next());
+                    props.load(resources.next());
 
                     if (result == null) {
                         result = props;
@@ -578,7 +589,7 @@
                 throw ne;
             }
             if (result == null) {
-                result = new Hashtable(11);
+                result = new Hashtable<>(11);
             }
             propertiesCache.put(cl, result);
             return result;
@@ -592,11 +603,10 @@
      * standard JNDI properties that specify colon-separated lists,
      * the values are concatenated and stored in props1.
      */
-    private static void mergeTables(Hashtable props1, Hashtable props2) {
-        Enumeration keys = props2.keys();
-
-        while (keys.hasMoreElements()) {
-            String prop = (String)keys.nextElement();
+    private static void mergeTables(Hashtable<? super String, Object> props1,
+                                    Hashtable<? super String, Object> props2) {
+        for (Object key : props2.keySet()) {
+            String prop = (String)key;
             Object val1 = props1.get(prop);
             if (val1 == null) {
                 props1.put(prop, props2.get(prop));
--- a/src/share/classes/com/sun/naming/internal/VersionHelper.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/naming/internal/VersionHelper.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,6 @@
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Enumeration;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -78,13 +77,13 @@
         return helper;
     }
 
-    public abstract Class loadClass(String className)
+    public abstract Class<?> loadClass(String className)
         throws ClassNotFoundException;
 
-    abstract Class loadClass(String className, ClassLoader cl)
+    abstract Class<?> loadClass(String className, ClassLoader cl)
         throws ClassNotFoundException;
 
-    public abstract Class loadClass(String className, String codebase)
+    public abstract Class<?> loadClass(String className, String codebase)
         throws ClassNotFoundException, MalformedURLException;
 
     /*
@@ -106,7 +105,7 @@
      * Returns the resource of a given name associated with a particular
      * class (never null), or null if none can be found.
      */
-    abstract InputStream getResourceAsStream(Class c, String name);
+    abstract InputStream getResourceAsStream(Class<?> c, String name);
 
     /*
      * Returns an input stream for a file in <java.home>/lib,
@@ -122,7 +121,8 @@
      * loader.  Null represents the bootstrap class loader in some
      * Java implementations.
      */
-    abstract NamingEnumeration getResources(ClassLoader cl, String name)
+    abstract NamingEnumeration<InputStream> getResources(
+            ClassLoader cl, String name)
         throws IOException;
 
     /*
@@ -137,13 +137,13 @@
         throws MalformedURLException {
         // Parse codebase into separate URLs
         StringTokenizer parser = new StringTokenizer(codebase);
-        Vector vec = new Vector(10);
+        Vector<String> vec = new Vector<>(10);
         while (parser.hasMoreTokens()) {
             vec.addElement(parser.nextToken());
         }
         String[] url = new String[vec.size()];
         for (int i = 0; i < url.length; i++) {
-            url[i] = (String)vec.elementAt(i);
+            url[i] = vec.elementAt(i);
         }
 
         URL[] urlArray = new URL[url.length];
--- a/src/share/classes/com/sun/naming/internal/VersionHelper12.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/com/sun/naming/internal/VersionHelper12.java	Mon Jan 30 08:02:44 2017 +0000
@@ -57,7 +57,7 @@
     VersionHelper12() {
     }
 
-    public Class loadClass(String className) throws ClassNotFoundException {
+    public Class<?> loadClass(String className) throws ClassNotFoundException {
         return loadClass(className, getContextClassLoader());
     }
 
@@ -67,7 +67,7 @@
      * This internal method is used with Thread Context Class Loader (TCCL),
      * please don't expose this method as public.
      */
-    Class loadClass(String className, ClassLoader cl)
+    Class<?> loadClass(String className, ClassLoader cl)
         throws ClassNotFoundException {
         Class<?> cls = Class.forName(className, true, cl);
         return cls;
@@ -77,7 +77,7 @@
      * @param className A non-null fully qualified class name.
      * @param codebase A non-null, space-separated list of URL strings.
      */
-    public Class loadClass(String className, String codebase)
+    public Class<?> loadClass(String className, String codebase)
         throws ClassNotFoundException, MalformedURLException {
 
         ClassLoader parent = getContextClassLoader();
@@ -88,9 +88,9 @@
     }
 
     String getJndiProperty(final int i) {
-        return (String) AccessController.doPrivileged(
-            new PrivilegedAction() {
-                public Object run() {
+        return AccessController.doPrivileged(
+            new PrivilegedAction<String>() {
+                public String run() {
                     try {
                         return System.getProperty(PROPS[i]);
                     } catch (SecurityException e) {
@@ -102,9 +102,9 @@
     }
 
     String[] getJndiProperties() {
-        Properties sysProps = (Properties) AccessController.doPrivileged(
-            new PrivilegedAction() {
-                public Object run() {
+        Properties sysProps = AccessController.doPrivileged(
+            new PrivilegedAction<Properties>() {
+                public Properties run() {
                     try {
                         return System.getProperties();
                     } catch (SecurityException e) {
@@ -123,10 +123,10 @@
         return jProps;
     }
 
-    InputStream getResourceAsStream(final Class c, final String name) {
-        return (InputStream) AccessController.doPrivileged(
-            new PrivilegedAction() {
-                public Object run() {
+    InputStream getResourceAsStream(final Class<?> c, final String name) {
+        return AccessController.doPrivileged(
+            new PrivilegedAction<InputStream>() {
+                public InputStream run() {
                     return c.getResourceAsStream(name);
                 }
             }
@@ -134,9 +134,9 @@
     }
 
     InputStream getJavaHomeLibStream(final String filename) {
-        return (InputStream) AccessController.doPrivileged(
-            new PrivilegedAction() {
-                public Object run() {
+        return AccessController.doPrivileged(
+            new PrivilegedAction<InputStream>() {
+                public InputStream run() {
                     try {
                         String javahome = System.getProperty("java.home");
                         if (javahome == null) {
@@ -153,14 +153,13 @@
         );
     }
 
-    NamingEnumeration getResources(final ClassLoader cl, final String name)
-            throws IOException
-    {
-        Enumeration urls;
+    NamingEnumeration<InputStream> getResources(final ClassLoader cl,
+            final String name) throws IOException {
+        Enumeration<URL> urls;
         try {
-            urls = (Enumeration) AccessController.doPrivileged(
-                new PrivilegedExceptionAction() {
-                    public Object run() throws IOException {
+            urls = AccessController.doPrivileged(
+                new PrivilegedExceptionAction<Enumeration<URL>>() {
+                    public Enumeration<URL> run() throws IOException {
                         return (cl == null)
                             ? ClassLoader.getSystemResources(name)
                             : cl.getResources(name);
@@ -182,9 +181,9 @@
      * Please don't expose this method as public.
      */
     ClassLoader getContextClassLoader() {
-        return (ClassLoader) AccessController.doPrivileged(
-            new PrivilegedAction() {
-                public Object run() {
+        return AccessController.doPrivileged(
+            new PrivilegedAction<ClassLoader>() {
+                public ClassLoader run() {
                     ClassLoader loader =
                             Thread.currentThread().getContextClassLoader();
                     if (loader == null) {
@@ -205,13 +204,13 @@
      * This is used to enumerate the resources under a foreign codebase.
      * This class is not MT-safe.
      */
-    class InputStreamEnumeration implements NamingEnumeration {
+    class InputStreamEnumeration implements NamingEnumeration<InputStream> {
 
-        private final Enumeration urls;
+        private final Enumeration<URL> urls;
 
-        private Object nextElement = null;
+        private InputStream nextElement = null;
 
-        InputStreamEnumeration(Enumeration urls) {
+        InputStreamEnumeration(Enumeration<URL> urls) {
             this.urls = urls;
         }
 
@@ -219,13 +218,13 @@
          * Returns the next InputStream, or null if there are no more.
          * An InputStream that cannot be opened is skipped.
          */
-        private Object getNextElement() {
+        private InputStream getNextElement() {
             return AccessController.doPrivileged(
-                new PrivilegedAction() {
-                    public Object run() {
+                new PrivilegedAction<InputStream>() {
+                    public InputStream run() {
                         while (urls.hasMoreElements()) {
                             try {
-                                return ((URL)urls.nextElement()).openStream();
+                                return urls.nextElement().openStream();
                             } catch (IOException e) {
                                 // skip this URL
                             }
@@ -248,9 +247,9 @@
             return hasMore();
         }
 
-        public Object next() {
+        public InputStream next() {
             if (hasMore()) {
-                Object res = nextElement;
+                InputStream res = nextElement;
                 nextElement = null;
                 return res;
             } else {
@@ -258,7 +257,7 @@
             }
         }
 
-        public Object nextElement() {
+        public InputStream nextElement() {
             return next();
         }
 
--- a/src/share/classes/javax/naming/CompositeName.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/CompositeName.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -394,7 +394,7 @@
       *         If posn is outside the specified range.
       */
     public Name getPrefix(int posn) {
-        Enumeration comps = impl.getPrefix(posn);
+        Enumeration<String> comps = impl.getPrefix(posn);
         return (new CompositeName(comps));
     }
 
@@ -412,7 +412,7 @@
       *         If posn is outside the specified range.
       */
     public Name getSuffix(int posn) {
-        Enumeration comps = impl.getSuffix(posn);
+        Enumeration<String> comps = impl.getSuffix(posn);
         return (new CompositeName(comps));
     }
 
@@ -563,7 +563,7 @@
     private void writeObject(java.io.ObjectOutputStream s)
             throws java.io.IOException {
         s.writeInt(size());
-        Enumeration comps = getAll();
+        Enumeration<String> comps = getAll();
         while (comps.hasMoreElements()) {
             s.writeObject(comps.nextElement());
         }
--- a/src/share/classes/javax/naming/CompoundName.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/CompoundName.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -376,7 +376,7 @@
       *         If posn is outside the specified range.
       */
     public Name getPrefix(int posn) {
-        Enumeration comps = impl.getPrefix(posn);
+        Enumeration<String> comps = impl.getPrefix(posn);
         return (new CompoundName(comps, mySyntax));
     }
 
@@ -396,7 +396,7 @@
       *         If posn is outside the specified range.
       */
     public Name getSuffix(int posn) {
-        Enumeration comps = impl.getSuffix(posn);
+        Enumeration<String> comps = impl.getSuffix(posn);
         return (new CompoundName(comps, mySyntax));
     }
 
@@ -557,7 +557,7 @@
             throws java.io.IOException {
         s.writeObject(mySyntax);
         s.writeInt(size());
-        Enumeration comps = getAll();
+        Enumeration<String> comps = getAll();
         while (comps.hasMoreElements()) {
             s.writeObject(comps.nextElement());
         }
--- a/src/share/classes/javax/naming/InitialContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/InitialContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -232,10 +232,12 @@
      * @see #InitialContext(boolean)
      * @since 1.3
      */
+    @SuppressWarnings("unchecked")
     protected void init(Hashtable<?,?> environment)
         throws NamingException
     {
-        myProps = ResourceManager.getInitialEnvironment(environment);
+        myProps = (Hashtable<Object,Object>)
+                ResourceManager.getInitialEnvironment(environment);
 
         if (myProps.get(Context.INITIAL_CONTEXT_FACTORY) != null) {
             // user has specified initial context factory; try to get it
@@ -265,6 +267,7 @@
      * @see #lookup(Name)
      * @since 1.6
      */
+    @SuppressWarnings("unchecked")
     public static <T> T doLookup(Name name)
         throws NamingException {
         return (T) (new InitialContext()).lookup(name);
@@ -279,6 +282,7 @@
      * @throws  NamingException if a naming exception is encountered
       * @since 1.6
      */
+    @SuppressWarnings("unchecked")
     public static <T> T doLookup(String name)
         throws NamingException {
         return (T) (new InitialContext()).lookup(name);
--- a/src/share/classes/javax/naming/NameImpl.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/NameImpl.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,7 @@
     private static final byte RIGHT_TO_LEFT = 2;
     private static final byte FLAT = 0;
 
-    private Vector components;
+    private Vector<String> components;
 
     private byte syntaxDirection = LEFT_TO_RIGHT;
     private String syntaxSeparator = "/";
@@ -97,7 +97,7 @@
         return (i);
     }
 
-    private final int extractComp(String name, int i, int len, Vector comps)
+    private final int extractComp(String name, int i, int len, Vector<String> comps)
     throws InvalidNameException {
         String beginQuote;
         String endQuote;
@@ -270,7 +270,7 @@
         if (syntax != null) {
             recordNamingConvention(syntax);
         }
-        components = new Vector();
+        components = new Vector<>();
     }
 
     NameImpl(Properties syntax, String n) throws InvalidNameException {
@@ -284,8 +284,8 @@
             i = extractComp(n, i, len, components);
 
             String comp = rToL
-                ? (String)components.firstElement()
-                : (String)components.lastElement();
+                ? components.firstElement()
+                : components.lastElement();
             if (comp.length() >= 1) {
                 compsAllEmpty = false;
             }
@@ -304,7 +304,7 @@
         }
     }
 
-    NameImpl(Properties syntax, Enumeration comps) {
+    NameImpl(Properties syntax, Enumeration<String> comps) {
         this(syntax);
 
         // %% comps could shrink in the middle.
@@ -455,9 +455,9 @@
         for (int i = 0; i < size; i++) {
             if (syntaxDirection == RIGHT_TO_LEFT) {
                 comp =
-                    stringifyComp((String) components.elementAt(size - 1 - i));
+                    stringifyComp(components.elementAt(size - 1 - i));
             } else {
-                comp = stringifyComp((String) components.elementAt(i));
+                comp = stringifyComp(components.elementAt(i));
             }
             if ((i != 0) && (syntaxSeparator != null))
                 answer.append(syntaxSeparator);
@@ -474,12 +474,12 @@
         if ((obj != null) && (obj instanceof NameImpl)) {
             NameImpl target = (NameImpl)obj;
             if (target.size() ==  this.size()) {
-                Enumeration mycomps = getAll();
-                Enumeration comps = target.getAll();
+                Enumeration<String> mycomps = getAll();
+                Enumeration<String> comps = target.getAll();
                 while (mycomps.hasMoreElements()) {
                     // %% comps could shrink in the middle.
-                    String my = (String)mycomps.nextElement();
-                    String his = (String)comps.nextElement();
+                    String my = mycomps.nextElement();
+                    String his = comps.nextElement();
                     if (syntaxTrimBlanks) {
                         my = my.trim();
                         his = his.trim();
@@ -543,22 +543,22 @@
         return (components.size());
     }
 
-    public Enumeration getAll() {
+    public Enumeration<String> getAll() {
         return components.elements();
     }
 
     public String get(int posn) {
-        return ((String) components.elementAt(posn));
+        return components.elementAt(posn);
     }
 
-    public Enumeration getPrefix(int posn) {
+    public Enumeration<String> getPrefix(int posn) {
         if (posn < 0 || posn > size()) {
             throw new ArrayIndexOutOfBoundsException(posn);
         }
         return new NameImplEnumerator(components, 0, posn);
     }
 
-    public Enumeration getSuffix(int posn) {
+    public Enumeration<String> getSuffix(int posn) {
         int cnt = size();
         if (posn < 0 || posn > cnt) {
             throw new ArrayIndexOutOfBoundsException(posn);
@@ -570,15 +570,15 @@
         return (components.isEmpty());
     }
 
-    public boolean startsWith(int posn, Enumeration prefix) {
+    public boolean startsWith(int posn, Enumeration<String> prefix) {
         if (posn < 0 || posn > size()) {
             return false;
         }
         try {
-            Enumeration mycomps = getPrefix(posn);
+            Enumeration<String> mycomps = getPrefix(posn);
             while (mycomps.hasMoreElements()) {
-                String my = (String)mycomps.nextElement();
-                String his = (String)prefix.nextElement();
+                String my = mycomps.nextElement();
+                String his = prefix.nextElement();
                 if (syntaxTrimBlanks) {
                     my = my.trim();
                     his = his.trim();
@@ -597,7 +597,7 @@
         return true;
     }
 
-    public boolean endsWith(int posn, Enumeration suffix) {
+    public boolean endsWith(int posn, Enumeration<String> suffix) {
         // posn is number of elements in suffix
         // startIndex is the starting position in this name
         // at which to start the comparison. It is calculated by
@@ -607,10 +607,10 @@
             return false;
         }
         try {
-            Enumeration mycomps = getSuffix(startIndex);
+            Enumeration<String> mycomps = getSuffix(startIndex);
             while (mycomps.hasMoreElements()) {
-                String my = (String)mycomps.nextElement();
-                String his = (String)suffix.nextElement();
+                String my = mycomps.nextElement();
+                String his = suffix.nextElement();
                 if (syntaxTrimBlanks) {
                     my = my.trim();
                     his = his.trim();
@@ -629,11 +629,11 @@
         return true;
     }
 
-    public boolean addAll(Enumeration comps) throws InvalidNameException {
+    public boolean addAll(Enumeration<String> comps) throws InvalidNameException {
         boolean added = false;
         while (comps.hasMoreElements()) {
             try {
-                Object comp = comps.nextElement();
+                String comp = comps.nextElement();
                 if (size() > 0 && syntaxDirection == FLAT) {
                     throw new InvalidNameException(
                         "A flat name can only have a single component");
@@ -647,12 +647,12 @@
         return added;
     }
 
-    public boolean addAll(int posn, Enumeration comps)
+    public boolean addAll(int posn, Enumeration<String> comps)
     throws InvalidNameException {
         boolean added = false;
         for (int i = posn; comps.hasMoreElements(); i++) {
             try {
-                Object comp = comps.nextElement();
+                String comp = comps.nextElement();
                 if (size() > 0 && syntaxDirection == FLAT) {
                     throw new InvalidNameException(
                         "A flat name can only have a single component");
@@ -690,8 +690,8 @@
 
     public int hashCode() {
         int hash = 0;
-        for (Enumeration e = getAll(); e.hasMoreElements();) {
-            String comp = (String)e.nextElement();
+        for (Enumeration<String> e = getAll(); e.hasMoreElements();) {
+            String comp = e.nextElement();
             if (syntaxTrimBlanks) {
                 comp = comp.trim();
             }
@@ -706,12 +706,12 @@
 }
 
 final
-class NameImplEnumerator implements Enumeration {
-    Vector vector;
+class NameImplEnumerator implements Enumeration<String> {
+    Vector<String> vector;
     int count;
     int limit;
 
-    NameImplEnumerator(Vector v, int start, int lim) {
+    NameImplEnumerator(Vector<String> v, int start, int lim) {
         vector = v;
         count = start;
         limit = lim;
@@ -721,7 +721,7 @@
         return count < limit;
     }
 
-    public Object nextElement() {
+    public String nextElement() {
         if (count < limit) {
             return vector.elementAt(count++);
         }
--- a/src/share/classes/javax/naming/Reference.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/Reference.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -120,7 +120,7 @@
       */
     public Reference(String className) {
         this.className  = className;
-        addrs = new Vector();
+        addrs = new Vector<>();
     }
 
     /**
@@ -134,7 +134,7 @@
       */
     public Reference(String className, RefAddr addr) {
         this.className = className;
-        addrs = new Vector();
+        addrs = new Vector<>();
         addrs.addElement(addr);
     }
 
@@ -225,7 +225,7 @@
         int len = addrs.size();
         RefAddr addr;
         for (int i = 0; i < len; i++) {
-            addr = (RefAddr) addrs.elementAt(i);
+            addr = addrs.elementAt(i);
             if (addr.getType().compareTo(addrType) == 0)
                 return addr;
         }
@@ -241,7 +241,7 @@
       *         range.
       */
     public RefAddr get(int posn) {
-        return ((RefAddr) addrs.elementAt(posn));
+        return addrs.elementAt(posn);
     }
 
     /**
@@ -331,8 +331,8 @@
             // ignore factory information
             if (target.className.equals(this.className) &&
                 target.size() ==  this.size()) {
-                Enumeration mycomps = getAll();
-                Enumeration comps = target.getAll();
+                Enumeration<RefAddr> mycomps = getAll();
+                Enumeration<RefAddr> comps = target.getAll();
                 while (mycomps.hasMoreElements())
                     if (!(mycomps.nextElement().equals(comps.nextElement())))
                         return false;
@@ -350,7 +350,7 @@
       */
     public int hashCode() {
         int hash = className.hashCode();
-        for (Enumeration e = getAll(); e.hasMoreElements();)
+        for (Enumeration<RefAddr> e = getAll(); e.hasMoreElements();)
             hash += e.nextElement().hashCode();
         return hash;
     }
@@ -382,7 +382,7 @@
     public Object clone() {
         Reference r = new Reference(className, classFactory, classFactoryLocation);
         Enumeration<RefAddr> a = getAll();
-        r.addrs = new Vector();
+        r.addrs = new Vector<>();
 
         while (a.hasMoreElements())
             r.addrs.addElement(a.nextElement());
--- a/src/share/classes/javax/naming/directory/BasicAttribute.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/directory/BasicAttribute.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -91,6 +91,7 @@
      */
     protected boolean ordered = false;
 
+    @SuppressWarnings("unchecked")
     public Object clone() {
         BasicAttribute attr;
         try {
@@ -98,7 +99,7 @@
         } catch (CloneNotSupportedException e) {
             attr = new BasicAttribute(attrID, ordered);
         }
-        attr.values = (Vector)values.clone();
+        attr.values = (Vector<Object>)values.clone();
         return attr;
     }
 
@@ -149,7 +150,7 @@
                         }
                     } else {
                         // order is not relevant; check for existence
-                        Enumeration theirs = target.getAll();
+                        Enumeration<?> theirs = target.getAll();
                         while (theirs.hasMoreElements()) {
                             if (find(theirs.nextElement()) < 0)
                                 return false;
@@ -215,7 +216,7 @@
             answer.append("No values");
         } else {
             boolean start = true;
-            for (Enumeration e = values.elements(); e.hasMoreElements(); ) {
+            for (Enumeration<Object> e = values.elements(); e.hasMoreElements(); ) {
                 if (!start)
                     answer.append(", ");
                 answer.append(e.nextElement());
@@ -254,7 +255,7 @@
       */
     public BasicAttribute(String id, boolean ordered) {
         attrID = id;
-        values = new Vector();
+        values = new Vector<>();
         this.ordered = ordered;
     }
 
@@ -327,7 +328,7 @@
     // For finding first element that has a null in JDK1.1 Vector.
     // In the Java 2 platform, can just replace this with Vector.indexOf(target);
     private int find(Object target) {
-        Class cl;
+        Class<?> cl;
         if (target == null) {
             int ct = values.size();
             for (int i = 0 ; i < ct ; i++) {
@@ -514,7 +515,7 @@
             throws java.io.IOException, ClassNotFoundException {
         s.defaultReadObject();  // read in the attrID
         int n = s.readInt();    // number of values
-        values = new Vector(n);
+        values = new Vector<>(n);
         while (--n >= 0) {
             values.addElement(s.readObject());
         }
@@ -522,31 +523,31 @@
 
 
     class ValuesEnumImpl implements NamingEnumeration<Object> {
-    Enumeration list;
+        Enumeration<Object> list;
 
-    ValuesEnumImpl() {
-        list = values.elements();
-    }
+        ValuesEnumImpl() {
+            list = values.elements();
+        }
 
-    public boolean hasMoreElements() {
-        return list.hasMoreElements();
-    }
+        public boolean hasMoreElements() {
+            return list.hasMoreElements();
+        }
 
-    public Object nextElement() {
-        return(list.nextElement());
-    }
+        public Object nextElement() {
+            return(list.nextElement());
+        }
 
-    public Object next() throws NamingException {
-        return list.nextElement();
-    }
+        public Object next() throws NamingException {
+            return list.nextElement();
+        }
 
-    public boolean hasMore() throws NamingException {
-        return list.hasMoreElements();
-    }
+        public boolean hasMore() throws NamingException {
+            return list.hasMoreElements();
+        }
 
-    public void close() throws NamingException {
-        list = null;
-    }
+        public void close() throws NamingException {
+            list = null;
+        }
     }
 
     /**
--- a/src/share/classes/javax/naming/directory/BasicAttributes.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/directory/BasicAttributes.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -78,7 +78,7 @@
     // If ignoreCase is true, key is aways lowercase.
     // If ignoreCase is false, key is stored as supplied by put().
     // %%% Not declared "private" due to bug 4064984.
-    transient Hashtable attrs = new Hashtable(11);
+    transient Hashtable<String,Attribute> attrs = new Hashtable<>(11);
 
     /**
       * Constructs a new instance of Attributes.
@@ -138,6 +138,7 @@
         this.put(new BasicAttribute(attrID, val));
     }
 
+    @SuppressWarnings("unchecked")
     public Object clone() {
         BasicAttributes attrset;
         try {
@@ -145,7 +146,7 @@
         } catch (CloneNotSupportedException e) {
             attrset = new BasicAttributes(ignoreCase);
         }
-        attrset.attrs = (Hashtable)attrs.clone();
+        attrset.attrs = (Hashtable<String,Attribute>)attrs.clone();
         return attrset;
     }
 
@@ -158,7 +159,7 @@
     }
 
     public Attribute get(String attrID) {
-        Attribute attr = (Attribute) attrs.get(
+        Attribute attr = attrs.get(
                 ignoreCase ? attrID.toLowerCase() : attrID);
         return (attr);
     }
@@ -180,12 +181,12 @@
         if (ignoreCase) {
             id = id.toLowerCase();
         }
-        return (Attribute)attrs.put(id, attr);
+        return attrs.put(id, attr);
     }
 
     public Attribute remove(String attrID) {
         String id = (ignoreCase ? attrID.toLowerCase() : attrID);
-        return (Attribute)attrs.remove(id);
+        return attrs.remove(id);
     }
 
     /**
@@ -234,7 +235,7 @@
             if (size() == target.size()) {
                 Attribute their, mine;
                 try {
-                    NamingEnumeration theirs = target.getAll();
+                    NamingEnumeration<?> theirs = target.getAll();
                     while (theirs.hasMore()) {
                         their = (Attribute)theirs.next();
                         mine = get(their.getID());
@@ -268,7 +269,7 @@
     public int hashCode() {
         int hash = (ignoreCase ? 1 : 0);
         try {
-            NamingEnumeration all = getAll();
+            NamingEnumeration<?> all = getAll();
             while (all.hasMore()) {
                 hash += all.next().hashCode();
             }
@@ -286,7 +287,7 @@
             throws java.io.IOException {
         s.defaultWriteObject(); // write out the ignoreCase flag
         s.writeInt(attrs.size());
-        Enumeration attrEnum = attrs.elements();
+        Enumeration<Attribute> attrEnum = attrs.elements();
         while (attrEnum.hasMoreElements()) {
             s.writeObject(attrEnum.nextElement());
         }
@@ -300,8 +301,8 @@
         s.defaultReadObject();  // read in the ignoreCase flag
         int n = s.readInt();    // number of attributes
         attrs = (n >= 1)
-            ? new Hashtable(n * 2)
-            : new Hashtable(2); // can't have initial size of 0 (grrr...)
+            ? new Hashtable<String,Attribute>(n * 2)
+            : new Hashtable<String,Attribute>(2); // can't have initial size of 0 (grrr...)
         while (--n >= 0) {
             put((Attribute)s.readObject());
         }
--- a/src/share/classes/javax/naming/ldap/InitialLdapContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/ldap/InitialLdapContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -129,15 +129,16 @@
      * @see #reconnect
      * @see LdapContext#reconnect
      */
+    @SuppressWarnings("unchecked")
     public InitialLdapContext(Hashtable<?,?> environment,
                               Control[] connCtls)
             throws NamingException {
         super(true); // don't initialize yet
 
         // Clone environment since caller owns it.
-        Hashtable env = (environment == null)
-            ? new Hashtable(11)
-            : (Hashtable)environment.clone();
+        Hashtable<Object,Object> env = (environment == null)
+            ? new Hashtable<>(11)
+            : (Hashtable<Object,Object>)environment.clone();
 
         // Put connect controls into environment.  Copy them first since
         // caller owns the array.
--- a/src/share/classes/javax/naming/ldap/LdapName.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/ldap/LdapName.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -104,9 +104,7 @@
 
 public class LdapName implements Name {
 
-    // private transient ArrayList<Rdn> rdns;   // parsed name components
-
-    private transient ArrayList rdns;   // parsed name components
+    private transient List<Rdn> rdns;   // parsed name components
     private transient String unparsed;  // if non-null, the DN in unparsed form
     private static final long serialVersionUID = -1595520034788997356L;
 
@@ -144,14 +142,14 @@
         //              "Invalid entries, list entries must be of type Rdn");
         //  }
 
-        this.rdns = new ArrayList(rdns.size());
+        this.rdns = new ArrayList<>(rdns.size());
         for (int i = 0; i < rdns.size(); i++) {
             Object obj = rdns.get(i);
             if (!(obj instanceof Rdn)) {
                 throw new IllegalArgumentException("Entry:" + obj +
                         "  not a valid type;list entries must be of type Rdn");
             }
-            this.rdns.add(obj);
+            this.rdns.add((Rdn)obj);
         }
     }
 
@@ -161,14 +159,12 @@
      * (if "name" is not null), the unparsed DN.
      *
      */
-    // private LdapName(String name, List<Rdn> rdns, int beg, int end) {
-
-    private LdapName(String name, ArrayList rdns, int beg, int end) {
+    private LdapName(String name, List<Rdn> rdns, int beg, int end) {
         unparsed = name;
         // this.rdns = rdns.subList(beg, end);
 
-        List sList = rdns.subList(beg, end);
-        this.rdns = new ArrayList(sList);
+        List<Rdn> sList = rdns.subList(beg, end);
+        this.rdns = new ArrayList<>(sList);
     }
 
     /**
@@ -201,7 +197,7 @@
      * Each element of the enumeration is of class String.
      */
     public Enumeration<String> getAll() {
-        final Iterator iter = rdns.iterator();
+        final Iterator<Rdn> iter = rdns.iterator();
 
         return new Enumeration<String>() {
             public boolean hasMoreElements() {
@@ -234,7 +230,7 @@
      *            specified range.
      */
     public Rdn getRdn(int posn) {
-        return (Rdn) rdns.get(posn);
+        return rdns.get(posn);
     }
 
     /**
@@ -370,7 +366,7 @@
                 doesListMatch(len1 - len2, len1, rdns));
     }
 
-    private boolean doesListMatch(int beg, int end, List rdns) {
+    private boolean doesListMatch(int beg, int end, List<Rdn> rdns) {
         for (int i = beg; i < end; i++) {
             if (!this.rdns.get(i).equals(rdns.get(i - beg))) {
                 return false;
@@ -457,10 +453,10 @@
             LdapName s = (LdapName) suffix;
             rdns.addAll(posn, s.rdns);
         } else {
-            Enumeration comps = suffix.getAll();
+            Enumeration<String> comps = suffix.getAll();
             while (comps.hasMoreElements()) {
                 rdns.add(posn++,
-                    (new Rfc2253Parser((String) comps.nextElement()).
+                    (new Rfc2253Parser(comps.nextElement()).
                     parseRdn()));
             }
         }
@@ -489,7 +485,7 @@
                 throw new IllegalArgumentException("Entry:" + obj +
                 "  not a valid type;suffix list entries must be of type Rdn");
             }
-            rdns.add(i + posn, obj);
+            rdns.add(i + posn, (Rdn)obj);
         }
         return this;
     }
@@ -627,11 +623,11 @@
         StringBuilder builder = new StringBuilder();
         int size = rdns.size();
         if ((size - 1) >= 0) {
-            builder.append((Rdn) rdns.get(size - 1));
+            builder.append(rdns.get(size - 1));
         }
         for (int next = size - 2; next >= 0; next--) {
             builder.append(',');
-            builder.append((Rdn) rdns.get(next));
+            builder.append(rdns.get(next));
         }
         unparsed = builder.toString();
         return unparsed;
@@ -672,8 +668,8 @@
         // Compare RDNs one by one for equality
         for (int i = 0; i < rdns.size(); i++) {
             // Compare a single pair of RDNs.
-            Rdn rdn1 = (Rdn) rdns.get(i);
-            Rdn rdn2 = (Rdn) that.rdns.get(i);
+            Rdn rdn1 = rdns.get(i);
+            Rdn rdn2 = that.rdns.get(i);
             if (!rdn1.equals(rdn2)) {
                 return false;
             }
@@ -727,8 +723,8 @@
         int minSize = Math.min(rdns.size(), that.rdns.size());
         for (int i = 0; i < minSize; i++) {
             // Compare a single pair of RDNs.
-            Rdn rdn1 = (Rdn)rdns.get(i);
-            Rdn rdn2 = (Rdn)that.rdns.get(i);
+            Rdn rdn1 = rdns.get(i);
+            Rdn rdn2 = that.rdns.get(i);
 
             int diff = rdn1.compareTo(rdn2);
             if (diff != 0) {
@@ -752,7 +748,7 @@
 
         // For each RDN...
         for (int i = 0; i < rdns.size(); i++) {
-            Rdn rdn = (Rdn) rdns.get(i);
+            Rdn rdn = rdns.get(i);
             hash += rdn.hashCode();
         }
         return hash;
@@ -786,6 +782,6 @@
     private void parse() throws InvalidNameException {
         // rdns = (ArrayList<Rdn>) (new RFC2253Parser(unparsed)).getDN();
 
-        rdns = (ArrayList) (new Rfc2253Parser(unparsed)).parseDn();
+        rdns = new Rfc2253Parser(unparsed).parseDn();
     }
 }
--- a/src/share/classes/javax/naming/ldap/Rdn.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/ldap/Rdn.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -104,8 +104,7 @@
 
 public class Rdn implements Serializable, Comparable<Object> {
 
-    // private transient ArrayList<RdnEntry> entries;
-    private transient ArrayList entries;
+    private transient ArrayList<RdnEntry> entries;
 
     // The common case.
     private static final int DEFAULT_SIZE = 1;
@@ -130,12 +129,12 @@
         if (attrSet.size() == 0) {
             throw new InvalidNameException("Attributes cannot be empty");
         }
-        entries = new ArrayList(attrSet.size());
-        NamingEnumeration attrs = attrSet.getAll();
+        entries = new ArrayList<>(attrSet.size());
+        NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
         try {
             for (int nEntries = 0; attrs.hasMore(); nEntries++) {
                 RdnEntry entry = new RdnEntry();
-                Attribute attr = (Attribute) attrs.next();
+                Attribute attr = attrs.next();
                 entry.type = attr.getID();
                 entry.value = attr.get();
                 entries.add(nEntries, entry);
@@ -161,7 +160,7 @@
      *                  parsing of the rdnString.
      */
     public Rdn(String rdnString) throws InvalidNameException {
-        entries = new ArrayList(DEFAULT_SIZE);
+        entries = new ArrayList<>(DEFAULT_SIZE);
         (new Rfc2253Parser(rdnString)).parseRdn(this);
     }
 
@@ -172,7 +171,7 @@
      * @param rdn The non-null Rdn to be copied.
      */
     public Rdn(Rdn rdn) {
-        entries = new ArrayList(rdn.entries.size());
+        entries = new ArrayList<>(rdn.entries.size());
         entries.addAll(rdn.entries);
     }
 
@@ -199,7 +198,7 @@
                 "type or value cannot be empty, type:" + type +
                 " value:" + value);
         }
-        entries = new ArrayList(DEFAULT_SIZE);
+        entries = new ArrayList<>(DEFAULT_SIZE);
         put(type, value);
     }
 
@@ -210,7 +209,7 @@
 
     // An empty constructor used by the parser
     Rdn() {
-        entries = new ArrayList(DEFAULT_SIZE);
+        entries = new ArrayList<>(DEFAULT_SIZE);
     }
 
     /*
@@ -257,7 +256,7 @@
      * @return The non-null attribute value.
      */
     public Object getValue() {
-        return ((RdnEntry) entries.get(0)).getValue();
+        return entries.get(0).getValue();
     }
 
     /**
@@ -275,7 +274,7 @@
      * @return The non-null attribute type.
      */
     public String getType() {
-        return ((RdnEntry) entries.get(0)).getType();
+        return entries.get(0).getType();
     }
 
     /**
@@ -329,8 +328,7 @@
         for (int i = 0; i < minSize; i++) {
 
             // Compare a single pair of type/value pairs.
-            int diff = ((RdnEntry) entries.get(i)).compareTo(
-                                        that.entries.get(i));
+            int diff = entries.get(i).compareTo(that.entries.get(i));
             if (diff != 0) {
                 return diff;
             }
@@ -408,7 +406,7 @@
     public Attributes toAttributes() {
         Attributes attrs = new BasicAttributes(true);
         for (int i = 0; i < entries.size(); i++) {
-            RdnEntry entry = (RdnEntry) entries.get(i);
+            RdnEntry entry = entries.get(i);
             Attribute attr = attrs.put(entry.getType(), entry.getValue());
             if (attr != null) {
                 attr.add(entry.getValue());
@@ -419,7 +417,7 @@
     }
 
 
-    private static class RdnEntry implements Comparable {
+    private static class RdnEntry implements Comparable<RdnEntry> {
         private String type;
         private Object value;
 
@@ -435,12 +433,7 @@
             return value;
         }
 
-        public int compareTo(Object obj) {
-
-            // Any change here affecting equality must be
-            // reflected in hashCode().
-            RdnEntry that = (RdnEntry) obj;
-
+        public int compareTo(RdnEntry that) {
             int diff = type.toUpperCase().compareTo(
                         that.type.toUpperCase());
             if (diff != 0) {
@@ -755,7 +748,7 @@
     private void readObject(ObjectInputStream s)
             throws IOException, ClassNotFoundException {
         s.defaultReadObject();
-        entries = new ArrayList(DEFAULT_SIZE);
+        entries = new ArrayList<>(DEFAULT_SIZE);
         String unparsed = (String) s.readObject();
         try {
             (new Rfc2253Parser(unparsed)).parseRdn(this);
--- a/src/share/classes/javax/naming/ldap/Rfc2253Parser.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/ldap/Rfc2253Parser.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -54,14 +54,14 @@
          */
         // public List<Rdn> getDN() throws InvalidNameException {
 
-        List parseDn() throws InvalidNameException {
+        List<Rdn> parseDn() throws InvalidNameException {
             cur = 0;
 
             // ArrayList<Rdn> rdns =
             //  new ArrayList<Rdn>(len / 3 + 10);  // leave room for growth
 
-            ArrayList rdns =
-                new ArrayList(len / 3 + 10);  // leave room for growth
+            ArrayList<Rdn> rdns =
+                new ArrayList<>(len / 3 + 10);  // leave room for growth
 
             if (len == 0) {
                 return rdns;
--- a/src/share/classes/javax/naming/ldap/StartTlsRequest.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/ldap/StartTlsRequest.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -192,7 +192,7 @@
         }
         try {
             VersionHelper helper = VersionHelper.getVersionHelper();
-            Class clas = helper.loadClass(
+            Class<?> clas = helper.loadClass(
                 "com.sun.jndi.ldap.ext.StartTlsResponseImpl");
 
             resp = (StartTlsResponse) clas.newInstance();
@@ -226,19 +226,19 @@
      * Acquire the class loader associated with this thread.
      */
     private final ClassLoader getContextClassLoader() {
-        return (ClassLoader) AccessController.doPrivileged(
-            new PrivilegedAction() {
-                public Object run() {
+        return AccessController.doPrivileged(
+            new PrivilegedAction<ClassLoader>() {
+                public ClassLoader run() {
                     return Thread.currentThread().getContextClassLoader();
                 }
             }
         );
     }
 
-    private final static boolean privilegedHasNext(final Iterator iter) {
-        Boolean answer = (Boolean) AccessController.doPrivileged(
-            new PrivilegedAction() {
-            public Object run() {
+    private final static boolean privilegedHasNext(final Iterator<StartTlsResponse> iter) {
+        Boolean answer = AccessController.doPrivileged(
+            new PrivilegedAction<Boolean>() {
+            public Boolean run() {
                 return Boolean.valueOf(iter.hasNext());
             }
         });
--- a/src/share/classes/javax/naming/spi/ContinuationContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/spi/ContinuationContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,11 +38,11 @@
 
 class ContinuationContext implements Context, Resolver {
     protected CannotProceedException cpe;
-    protected Hashtable env;
+    protected Hashtable<?,?> env;
     protected Context contCtx = null;
 
     protected ContinuationContext(CannotProceedException cpe,
-                        Hashtable env) {
+                        Hashtable<?,?> env) {
         this.cpe = cpe;
         this.env = env;
     }
@@ -109,24 +109,24 @@
         ctx.rename(name, newName);
     }
 
-    public NamingEnumeration list(Name name) throws NamingException {
+    public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
         Context ctx = getTargetContext();
         return ctx.list(name);
     }
-    public NamingEnumeration list(String name) throws NamingException {
+    public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
         Context ctx = getTargetContext();
         return ctx.list(name);
     }
 
 
-    public NamingEnumeration listBindings(Name name)
+    public NamingEnumeration<Binding> listBindings(Name name)
         throws NamingException
     {
         Context ctx = getTargetContext();
         return ctx.listBindings(name);
     }
 
-    public NamingEnumeration listBindings(String name) throws NamingException {
+    public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
         Context ctx = getTargetContext();
         return ctx.listBindings(name);
     }
@@ -193,7 +193,7 @@
         return ctx.removeFromEnvironment(propName);
     }
 
-    public Hashtable getEnvironment() throws NamingException {
+    public Hashtable<?,?> getEnvironment() throws NamingException {
         Context ctx = getTargetContext();
         return ctx.getEnvironment();
     }
--- a/src/share/classes/javax/naming/spi/ContinuationDirContext.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/spi/ContinuationDirContext.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,6 +38,7 @@
 import javax.naming.directory.DirContext;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 import javax.naming.directory.ModificationItem;
 
 /**
@@ -50,7 +51,7 @@
 
 class ContinuationDirContext extends ContinuationContext implements DirContext {
 
-    ContinuationDirContext(CannotProceedException cpe, Hashtable env) {
+    ContinuationDirContext(CannotProceedException cpe, Hashtable<?,?> env) {
         super(cpe, env);
     }
 
@@ -204,7 +205,7 @@
                 res.getDirContext().createSubcontext(res.getString(), attrs);
         }
 
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
                                     Attributes matchingAttributes,
                                     String[] attributesToReturn)
         throws NamingException  {
@@ -213,7 +214,7 @@
                                              attributesToReturn);
         }
 
-    public NamingEnumeration search(String name,
+    public NamingEnumeration<SearchResult> search(String name,
                                     Attributes matchingAttributes,
                                     String[] attributesToReturn)
         throws NamingException  {
@@ -223,13 +224,13 @@
                                              attributesToReturn);
         }
 
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
                                     Attributes matchingAttributes)
         throws NamingException  {
             DirContextNamePair res = getTargetContext(name);
             return res.getDirContext().search(res.getName(), matchingAttributes);
         }
-    public NamingEnumeration search(String name,
+    public NamingEnumeration<SearchResult> search(String name,
                                     Attributes matchingAttributes)
         throws NamingException  {
             DirContextStringPair res = getTargetContext(name);
@@ -237,7 +238,7 @@
                                              matchingAttributes);
         }
 
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
                                     String filter,
                                     SearchControls cons)
         throws NamingException {
@@ -245,7 +246,7 @@
             return res.getDirContext().search(res.getName(), filter, cons);
         }
 
-    public NamingEnumeration search(String name,
+    public NamingEnumeration<SearchResult> search(String name,
                                     String filter,
                                     SearchControls cons)
         throws NamingException {
@@ -253,7 +254,7 @@
             return res.getDirContext().search(res.getString(), filter, cons);
         }
 
-    public NamingEnumeration search(Name name,
+    public NamingEnumeration<SearchResult> search(Name name,
                                     String filterExpr,
                                     Object[] args,
                                     SearchControls cons)
@@ -263,7 +264,7 @@
                                              cons);
         }
 
-    public NamingEnumeration search(String name,
+    public NamingEnumeration<SearchResult> search(String name,
                                     String filterExpr,
                                     Object[] args,
                                     SearchControls cons)
--- a/src/share/classes/javax/naming/spi/DirectoryManager.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/spi/DirectoryManager.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -84,15 +84,16 @@
       *
       * @see NamingManager#getContinuationContext(CannotProceedException)
       */
+    @SuppressWarnings("unchecked")
     public static DirContext getContinuationDirContext(
             CannotProceedException cpe) throws NamingException {
 
-        Hashtable env = cpe.getEnvironment();
+        Hashtable<Object,Object> env = (Hashtable<Object,Object>)cpe.getEnvironment();
         if (env == null) {
-            env = new Hashtable(7);
+            env = new Hashtable<>(7);
         } else {
             // Make a (shallow) copy of the environment.
-            env = (Hashtable) env.clone();
+            env = (Hashtable<Object,Object>) env.clone();
         }
         env.put(CPE, cpe);
 
@@ -217,7 +218,7 @@
     }
 
     private static Object createObjectFromFactories(Object obj, Name name,
-            Context nameCtx, Hashtable environment, Attributes attrs)
+            Context nameCtx, Hashtable<?,?> environment, Attributes attrs)
         throws Exception {
 
         FactoryEnumeration factories = ResourceManager.getFactories(
--- a/src/share/classes/javax/naming/spi/NamingManager.java	Mon Jan 30 06:47:57 2017 +0000
+++ b/src/share/classes/javax/naming/spi/NamingManager.java	Mon Jan 30 08:02:44 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -139,7 +139,7 @@
         throws IllegalAccessException,
         InstantiationException,
         MalformedURLException {
-        Class clas = null;
+        Class<?> clas = null;
 
         // Try to use current class loader
         try {
@@ -172,7 +172,7 @@
      * @return factory created; null if cannot create
      */
     private static Object createObjectFromFactories(Object obj, Name name,
-            Context nameCtx, Hashtable environment) throws Exception {
+            Context nameCtx, Hashtable<?,?> environment) throws Exception {
 
         FactoryEnumeration factories = ResourceManager.getFactories(
             Context.OBJECT_FACTORIES, environment, nameCtx);
@@ -349,7 +349,7 @@
      * invoking a factory.
      */
     static Object processURLAddrs(Reference ref, Name name, Context nameCtx,
-                                  Hashtable environment)
+                                  Hashtable<?,?> environment)
             throws NamingException {
 
         for (int i = 0; i < ref.size(); i++) {
@@ -368,7 +368,7 @@
     }
 
     private static Object processURL(Object refInfo, Name name,
-                                     Context nameCtx, Hashtable environment)
+                                     Context nameCtx, Hashtable<?,?> environment)
             throws NamingException {
         Object answer;
 
@@ -427,7 +427,7 @@
      * @see #getObjectInstance
      */
     static Context getContext(Object obj, Name name, Context nameCtx,
-                              Hashtable environment) throws NamingException {
+                              Hashtable<?,?> environment) throws NamingException {
         Object answer;
 
         if (obj instanceof Context) {
@@ -452,7 +452,7 @@
 
     // Used by ContinuationContext
     static Resolver getResolver(Object obj, Name name, Context nameCtx,
-                                Hashtable environment) throws NamingException {
+                                Hashtable<?,?> environment) throws NamingException {
         Object answer;
 
         if (obj instanceof Resolver) {
@@ -585,7 +585,7 @@
      */
     private static Object getURLObject(String scheme, Object urlInfo,
                                        Name name, Context nameCtx,
-                                       Hashtable environment)
+                                       Hashtable<?,?> environment)
             throws NamingException {
 
         // e.g. "ftpURLContextFactory"
@@ -771,15 +771,16 @@
      * @return A non-null Context object for continuing the operation.
      * @exception NamingException If a naming exception occurred.
      */
+    @SuppressWarnings("unchecked")
     public static Context getContinuationContext(CannotProceedException cpe)
             throws NamingException {
 
-        Hashtable env = cpe.getEnvironment();
+        Hashtable<Object,Object> env = (Hashtable<Object,Object>)cpe.getEnvironment();
         if (env == null) {
-            env = new Hashtable(7);
+            env = new Hashtable<>(7);
         } else {
             // Make a (shallow) copy of the environment.
-            env = (Hashtable) env.clone();
+            env = (Hashtable<Object,Object>)env.clone();
         }
         env.put(CPE, cpe);