7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
authornaoto
Mon, 05 Dec 2011 17:08:52 -0800
changeset 11138 9121a1a92512
parent 11137 d5efdfdf72e0
child 11139 db0c2ff5e1ea
7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes Reviewed-by: okutsu, smarks
jdk/src/share/classes/java/util/Currency.java
jdk/src/share/classes/sun/util/LocaleServiceProviderPool.java
jdk/src/share/classes/sun/util/resources/LocaleData.java
--- a/jdk/src/share/classes/java/util/Currency.java	Mon Dec 05 16:30:32 2011 -0800
+++ b/jdk/src/share/classes/java/util/Currency.java	Mon Dec 05 17:08:52 2011 -0800
@@ -189,7 +189,7 @@
     private static final int VALID_FORMAT_VERSION = 1;
 
     static {
-        AccessController.doPrivileged(new PrivilegedAction() {
+        AccessController.doPrivileged(new PrivilegedAction<Object>() {
             public Object run() {
                 String homeDir = System.getProperty("java.home");
                 try {
@@ -431,7 +431,9 @@
             }
         }
 
-        return (Set<Currency>) available.clone();
+        @SuppressWarnings("unchecked")
+        Set<Currency> result = (Set<Currency>) available.clone();
+        return result;
     }
 
     /**
--- a/jdk/src/share/classes/sun/util/LocaleServiceProviderPool.java	Mon Dec 05 16:30:32 2011 -0800
+++ b/jdk/src/share/classes/sun/util/LocaleServiceProviderPool.java	Mon Dec 05 17:08:52 2011 -0800
@@ -58,7 +58,7 @@
      * A Map that holds singleton instances of this class.  Each instance holds a
      * set of provider implementations of a particular locale sensitive service.
      */
-    private static ConcurrentMap<Class, LocaleServiceProviderPool> poolOfPools =
+    private static ConcurrentMap<Class<? extends LocaleServiceProvider>, LocaleServiceProviderPool> poolOfPools =
         new ConcurrentHashMap<>();
 
     /**
@@ -147,6 +147,10 @@
     /**
      * Lazy loaded set of available locales.
      * Loading all locales is a very long operation.
+     *
+     * We know "providerClasses" contains classes that extends LocaleServiceProvider,
+     * but generic array creation is not allowed, thus the "unchecked" warning
+     * is suppressed here.
      */
     private static class AllAvailableLocales {
         /**
@@ -156,7 +160,9 @@
         static final Locale[] allAvailableLocales;
 
         static {
-            Class[] providerClasses = {
+            @SuppressWarnings("unchecked")
+            Class<LocaleServiceProvider>[] providerClasses =
+                        (Class<LocaleServiceProvider>[]) new Class<?>[] {
                 java.text.spi.BreakIteratorProvider.class,
                 java.text.spi.CollatorProvider.class,
                 java.text.spi.DateFormatProvider.class,
@@ -174,7 +180,7 @@
                 all.add(getLookupLocale(locale));
             }
 
-            for (Class providerClass : providerClasses) {
+            for (Class<LocaleServiceProvider> providerClass : providerClasses) {
                 LocaleServiceProviderPool pool =
                     LocaleServiceProviderPool.getPool(providerClass);
                 all.addAll(pool.getProviderLocales());
@@ -355,7 +361,6 @@
             }
             Locale bundleLocale = (bundle != null ? bundle.getLocale() : null);
             List<Locale> lookupLocales = getLookupLocales(locale);
-            P lsp;
             S providersObj = null;
 
             // check whether a provider has an implementation that's closer
@@ -375,7 +380,9 @@
                     }
                 }
                 if (provLoc.contains(current)) {
-                    lsp = (P)findProvider(current);
+                    // It is safe to assume that findProvider() returns the instance of type P.
+                    @SuppressWarnings("unchecked")
+                    P lsp = (P)findProvider(current);
                     if (lsp != null) {
                         providersObj = getter.getObject(lsp, locale, key, params);
                         if (providersObj != null) {
@@ -397,7 +404,9 @@
                     // JRE has it.
                     return null;
                 } else {
-                    lsp = (P)findProvider(bundleLocale);
+                    // It is safe to assume that findProvider() returns the instance of type P.
+                    @SuppressWarnings("unchecked")
+                    P lsp = (P)findProvider(bundleLocale);
                     if (lsp != null) {
                         providersObj = getter.getObject(lsp, locale, key, params);
                         if (providersObj != null) {
--- a/jdk/src/share/classes/sun/util/resources/LocaleData.java	Mon Dec 05 16:30:32 2011 -0800
+++ b/jdk/src/share/classes/sun/util/resources/LocaleData.java	Mon Dec 05 17:08:52 2011 -0800
@@ -137,8 +137,8 @@
     }
 
     private static ResourceBundle getBundle(final String baseName, final Locale locale) {
-        return (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
+        return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
+                public ResourceBundle run() {
                     return ResourceBundle.
                         getBundle(baseName, locale,
                                   LocaleDataResourceBundleControl.getRBControlInstance());