changeset 4564:9cd372de83b1

7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes Reviewed-by: naoto Contributed-by: edvard.wendelin@oracle.com
author naoto
date Wed, 11 Jan 2012 10:25:27 -0800
parents 9a2c591758d8
children d7450b1e436d
files src/share/classes/java/util/Currency.java src/share/classes/sun/util/LocaleServiceProviderPool.java src/share/classes/sun/util/resources/LocaleData.java
diffstat 3 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Currency.java	Wed Jan 11 10:18:11 2012 -0800
+++ b/src/share/classes/java/util/Currency.java	Wed Jan 11 10:25:27 2012 -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 {
@@ -433,7 +433,9 @@
             }
         }
 
-        return (Set<Currency>) available.clone();
+        @SuppressWarnings("unchecked")
+        Set<Currency> result = (Set<Currency>) available.clone();
+        return result;
     }
 
     /**
--- a/src/share/classes/sun/util/LocaleServiceProviderPool.java	Wed Jan 11 10:18:11 2012 -0800
+++ b/src/share/classes/sun/util/LocaleServiceProviderPool.java	Wed Jan 11 10:25:27 2012 -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/src/share/classes/sun/util/resources/LocaleData.java	Wed Jan 11 10:18:11 2012 -0800
+++ b/src/share/classes/sun/util/resources/LocaleData.java	Wed Jan 11 10:25:27 2012 -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());