提交 d76f9567 编写于 作者: N naoto

7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes

Reviewed-by: okutsu, smarks
上级 a571f6a0
...@@ -189,7 +189,7 @@ public final class Currency implements Serializable { ...@@ -189,7 +189,7 @@ public final class Currency implements Serializable {
private static final int VALID_FORMAT_VERSION = 1; private static final int VALID_FORMAT_VERSION = 1;
static { static {
AccessController.doPrivileged(new PrivilegedAction() { AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() { public Object run() {
String homeDir = System.getProperty("java.home"); String homeDir = System.getProperty("java.home");
try { try {
...@@ -431,7 +431,9 @@ public final class Currency implements Serializable { ...@@ -431,7 +431,9 @@ public final class Currency implements Serializable {
} }
} }
return (Set<Currency>) available.clone(); @SuppressWarnings("unchecked")
Set<Currency> result = (Set<Currency>) available.clone();
return result;
} }
/** /**
......
...@@ -58,7 +58,7 @@ public final class LocaleServiceProviderPool { ...@@ -58,7 +58,7 @@ public final class LocaleServiceProviderPool {
* A Map that holds singleton instances of this class. Each instance holds a * A Map that holds singleton instances of this class. Each instance holds a
* set of provider implementations of a particular locale sensitive service. * 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<>(); new ConcurrentHashMap<>();
/** /**
...@@ -147,6 +147,10 @@ public final class LocaleServiceProviderPool { ...@@ -147,6 +147,10 @@ public final class LocaleServiceProviderPool {
/** /**
* Lazy loaded set of available locales. * Lazy loaded set of available locales.
* Loading all locales is a very long operation. * 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 { private static class AllAvailableLocales {
/** /**
...@@ -156,7 +160,9 @@ public final class LocaleServiceProviderPool { ...@@ -156,7 +160,9 @@ public final class LocaleServiceProviderPool {
static final Locale[] allAvailableLocales; static final Locale[] allAvailableLocales;
static { static {
Class[] providerClasses = { @SuppressWarnings("unchecked")
Class<LocaleServiceProvider>[] providerClasses =
(Class<LocaleServiceProvider>[]) new Class<?>[] {
java.text.spi.BreakIteratorProvider.class, java.text.spi.BreakIteratorProvider.class,
java.text.spi.CollatorProvider.class, java.text.spi.CollatorProvider.class,
java.text.spi.DateFormatProvider.class, java.text.spi.DateFormatProvider.class,
...@@ -174,7 +180,7 @@ public final class LocaleServiceProviderPool { ...@@ -174,7 +180,7 @@ public final class LocaleServiceProviderPool {
all.add(getLookupLocale(locale)); all.add(getLookupLocale(locale));
} }
for (Class providerClass : providerClasses) { for (Class<LocaleServiceProvider> providerClass : providerClasses) {
LocaleServiceProviderPool pool = LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(providerClass); LocaleServiceProviderPool.getPool(providerClass);
all.addAll(pool.getProviderLocales()); all.addAll(pool.getProviderLocales());
...@@ -355,7 +361,6 @@ public final class LocaleServiceProviderPool { ...@@ -355,7 +361,6 @@ public final class LocaleServiceProviderPool {
} }
Locale bundleLocale = (bundle != null ? bundle.getLocale() : null); Locale bundleLocale = (bundle != null ? bundle.getLocale() : null);
List<Locale> lookupLocales = getLookupLocales(locale); List<Locale> lookupLocales = getLookupLocales(locale);
P lsp;
S providersObj = null; S providersObj = null;
// check whether a provider has an implementation that's closer // check whether a provider has an implementation that's closer
...@@ -375,7 +380,9 @@ public final class LocaleServiceProviderPool { ...@@ -375,7 +380,9 @@ public final class LocaleServiceProviderPool {
} }
} }
if (provLoc.contains(current)) { 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) { if (lsp != null) {
providersObj = getter.getObject(lsp, locale, key, params); providersObj = getter.getObject(lsp, locale, key, params);
if (providersObj != null) { if (providersObj != null) {
...@@ -397,7 +404,9 @@ public final class LocaleServiceProviderPool { ...@@ -397,7 +404,9 @@ public final class LocaleServiceProviderPool {
// JRE has it. // JRE has it.
return null; return null;
} else { } 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) { if (lsp != null) {
providersObj = getter.getObject(lsp, locale, key, params); providersObj = getter.getObject(lsp, locale, key, params);
if (providersObj != null) { if (providersObj != null) {
......
...@@ -137,8 +137,8 @@ public class LocaleData { ...@@ -137,8 +137,8 @@ public class LocaleData {
} }
private static ResourceBundle getBundle(final String baseName, final Locale locale) { private static ResourceBundle getBundle(final String baseName, final Locale locale) {
return (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
public Object run() { public ResourceBundle run() {
return ResourceBundle. return ResourceBundle.
getBundle(baseName, locale, getBundle(baseName, locale,
LocaleDataResourceBundleControl.getRBControlInstance()); LocaleDataResourceBundleControl.getRBControlInstance());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册