mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 22:15:31 +00:00
ICU-7308 Added Utility.getFallbackClassLoader() and call it from 4 different places recently updated. This change was made by Doug's suggestion.
X-SVN-Rev: 27257
This commit is contained in:
parent
d1df3c60de
commit
debc645c69
5 changed files with 23 additions and 39 deletions
|
@ -573,17 +573,8 @@ public class ICULocaleService extends ICUService {
|
|||
protected ClassLoader loader() {
|
||||
ClassLoader cl = getClass().getClassLoader();
|
||||
if (cl == null) {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
if (cl == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available for loading ICU resource bundles.");
|
||||
}
|
||||
}
|
||||
cl = Utility.getFallbackClassLoader();
|
||||
}
|
||||
|
||||
return cl;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,15 +92,7 @@ public class ICUResourceBundle extends UResourceBundle {
|
|||
static {
|
||||
ClassLoader loader = ICUData.class.getClassLoader();
|
||||
if (loader == null) {
|
||||
loader = Thread.currentThread().getContextClassLoader();
|
||||
if (loader == null) {
|
||||
loader = ClassLoader.getSystemClassLoader();
|
||||
if (loader == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available for ICUData");
|
||||
}
|
||||
}
|
||||
loader = Utility.getFallbackClassLoader();
|
||||
}
|
||||
ICU_DATA_CLASS_LOADER = loader;
|
||||
}
|
||||
|
|
|
@ -112,15 +112,7 @@ public class ResourceBundleWrapper extends UResourceBundle {
|
|||
protected static synchronized UResourceBundle instantiateBundle(String baseName, String localeID,
|
||||
ClassLoader root, boolean disableFallback) {
|
||||
if (root == null) {
|
||||
root = Thread.currentThread().getContextClassLoader();
|
||||
if (root == null) {
|
||||
root = ClassLoader.getSystemClassLoader();
|
||||
if (root == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available for resource bundle " + baseName);
|
||||
}
|
||||
}
|
||||
root = Utility.getFallbackClassLoader();
|
||||
}
|
||||
final ClassLoader cl = root;
|
||||
String name = baseName;
|
||||
|
|
|
@ -35,18 +35,10 @@ public abstract class URLHandler {
|
|||
try {
|
||||
InputStream is = URLHandler.class.getResourceAsStream(PROPNAME);
|
||||
if (is == null) {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
if (loader == null) {
|
||||
loader = ClassLoader.getSystemClassLoader();
|
||||
if (loader == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available for URLHandler");
|
||||
}
|
||||
}
|
||||
ClassLoader loader = Utility.getFallbackClassLoader();
|
||||
is = loader.getResourceAsStream(PROPNAME);
|
||||
}
|
||||
|
||||
|
||||
if (is != null) {
|
||||
Class<?>[] params = { URL.class };
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 1996-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -1829,4 +1829,21 @@ public final class Utility {
|
|||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a fallback class loader for loading ICU resource
|
||||
* @return A class loader
|
||||
*/
|
||||
public static ClassLoader getFallbackClassLoader() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
if (cl == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available.");
|
||||
}
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue