src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java

Print this page

        

@@ -46,15 +46,16 @@
  *
  * @author Scott Seligman
  * @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 {
         myEnv = null;
     }

@@ -73,11 +74,11 @@
       * If rename() is supported for a particular URL scheme,
       * getRootURLContext(), getURLPrefix(), and getURLSuffix()
       * 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
       * that of calling getRootURLContext().getRemainingName(), but
       * without the overhead of doing anything with the prefix like

@@ -485,31 +486,35 @@
         Name result = (Name)prefix.clone();
         result.addAll(name);
         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();
         }
     }
 
 /*
 // To test, declare getURLPrefix and getURLSuffix static.