--- old/src/share/classes/com/sun/naming/internal/ResourceManager.java 2011-07-27 17:26:09.154629600 -0700 +++ new/src/share/classes/com/sun/naming/internal/ResourceManager.java 2011-07-27 17:26:08.165530700 -0700 @@ -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; @@ -89,7 +87,9 @@ * One from application resource files is keyed on the thread's * context class loader. */ - private static final WeakHashMap propertiesCache = new WeakHashMap(11); + // WeakHashMap + private static final WeakHashMap> + propertiesCache = new WeakHashMap<>(11); /* * A cache of factory objects (ObjectFactory, StateFactory, ControlFactory). @@ -99,7 +99,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>>> + factoryCache = new WeakHashMap<>(11); /* * A cache of URL factory objects (ObjectFactory). @@ -110,8 +112,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>> + urlFactoryCache = new WeakHashMap<>(11); + private static final WeakReference NO_FACTORY = + new WeakReference<>(null); /** * A class to allow JNDI properties be specified as applet parameters @@ -152,10 +157,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); } } } @@ -183,12 +187,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); @@ -213,14 +219,14 @@ : helper.getJndiProperty(i); } if (val != null) { - env.put(props[i], val); + ((Hashtable)env).put(props[i], val); } } } // Merge the above with the values read from all application // resource files. Colon-separated lists are concatenated. - mergeTables(env, getApplicationResources()); + mergeTables((Hashtable)env, getApplicationResources()); return env; } @@ -244,7 +250,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 { @@ -305,8 +311,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) @@ -315,17 +321,18 @@ // Cache is based on context class loader and property val ClassLoader loader = helper.getContextClassLoader(); - Map perLoaderCache = null; + Map>> 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> factories = + perLoaderCache.get(facProp); if (factories != null) { // Cached list return factories.size() == 0 ? null @@ -334,13 +341,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(c, className)); } catch (Exception e) { // ignore ClassNotFoundException, IllegalArgumentException } @@ -388,8 +395,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); @@ -403,11 +411,11 @@ ClassLoader loader = helper.getContextClassLoader(); String key = classSuffix + " " + facProp; - Map perLoaderCache = null; + Map> 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); } } @@ -415,7 +423,7 @@ synchronized (perLoaderCache) { Object factory = null; - WeakReference factoryRef = (WeakReference) perLoaderCache.get(key); + WeakReference factoryRef = perLoaderCache.get(key); if (factoryRef == NO_FACTORY) { return null; } else if (factoryRef != null) { @@ -451,7 +459,7 @@ // Cache it. perLoaderCache.put(key, (factory != null) - ? new WeakReference(factory) + ? new WeakReference<>(factory) : NO_FACTORY); return factory; } @@ -468,16 +476,18 @@ * * @throws NamingException if an error occurs while reading the file. */ - private static Hashtable getProviderResource(Object obj) + private static Hashtable + 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 props = + propertiesCache.get(c); if (props != null) { return props; } @@ -518,22 +528,23 @@ * @throws NamingException if an error occurs while reading a resource * file. */ - private static Hashtable getApplicationResources() throws NamingException { + private static Hashtable getApplicationResources() + throws NamingException { ClassLoader cl = helper.getContextClassLoader(); synchronized (propertiesCache) { - Hashtable result = (Hashtable)propertiesCache.get(cl); + Hashtable result = propertiesCache.get(cl); if (result != null) { return result; } try { - NamingEnumeration resources = + NamingEnumeration 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; @@ -563,7 +574,7 @@ throw ne; } if (result == null) { - result = new Hashtable(11); + result = new Hashtable<>(11); } propertiesCache.put(cl, result); return result; @@ -577,11 +588,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 props1, + Hashtable props2) { + for (Object key : props2.keySet()) { + String prop = (String)key; Object val1 = props1.get(prop); if (val1 == null) { props1.put(prop, props2.get(prop));